local help

BlitzMax Forums/BlitzMax Beginners Area/local help

as for posting more code, thats it basically... thats the function and the function was in the loop and when you got HIT, the boolean hit became true and started the block, and it works when frame was a global.


Wait a minute, are you saying that the If/End If is a seperate function from the main game loop? Something like this?
Global Hit:Int = False

While Not GameOver
  UpdateShips()
  If Bullet Collides With Ship Then Hit = True
  Do Explosions()
Wend

Function DoExplosions()
  If Hit = True
    Local frame:int
    DrawImage Explosion,ShipX,ShipY,frame
   
    frame :+ .5
    If Frame > 6.0
      Hit = False
      Frame = 0
    End If
  End If
End Function

If that's the case, then it explains why frame keeps loosing it's value. Whenever the function ends, frame loses scope and has to be recreated the next time the function is called. By using Global instead of Local, you are then keeping the value between function calls, which is the proper way to do that. Don't worry about it interfering with another frame declared elsewhere in your code, Globals declared within a function remain Global only to that function.

Edit: Globals within a function act like static variables in C++