Static Variables

BlitzMax Forums/BlitzMax Programming/Static Variables

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I'm not sure if this is well known or not it is possible to have a static variable in a function.

To do so use a Global.

i.e.

strict 
Function MyTest(flag : int = 0)
   
   global static : int
  
   if flag = 0
      static:+1
   else
      print static
   end if

end function

for local i : int = 0 to 4
    MyTest()
next

MyTest(1)
End


Running the above example will print 5 instead of 1 as it would if a local variable were to be used in stead.

Cheers.