Hmmm... Cruis, I guess your main problem is understanding what is called "variable scope".
Variable scope describes when certain information is accessible. Local variables declared
inside If, When, For loops (etc) are only "accessible/visible" from within that block of code. Once you leave that block the variable no longer exists.
Here's a quick example, looking at the scope of a local variable "frame" :
While something = True
' frame doesn't exist here (not in scope)
If stuff = False Then
' frame doesn't exist *yet* (still not in scope)
Local frame:Int ' frame is set to zero
' frame is now in scope until the End If
DrawAFrame(frame)
frame:+ 1
If frame > 6 Then
' in this example, we'll never get here, because frame
' will always be 1 when we get here, because of "scope"
frame = 0
End if
End If
' frame doesn't exist here (not in scope)
Wend
When frame "goes out of scope" it ceases to exist. Therefore, the next time we want to use it, it is recreated (and hence its value is reset to zero)
Rather you do something like :
Local frame:Int ' frame is set to zero
' frame is now in scope...
While something = True
' frame is still in scope
If stuff = False Then
DrawAFrame(frame)
' since frame is still in scope, its value will increment
' as the program iterates over the While loop.
frame:+ 1
If frame > 6 Then
frame = 0
End if
End If
' frame is still in scope
Wend
' frame is still in scope here
As you can see, any nested blocks of code remember the scope of local variables declared before they are called.
.. Try googling for "variable scope" examples, which might help you to get a better understanding of the concept...