Static Variables
BlitzMax Forums/BlitzMax Programming/Static Variables
| ||
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. |
| ||
As far as I'm concerned, this is already common knowledge. On another note, you can have nested functions too. function foo() bar() function bar() print "called from foo" end function end function |
| ||
not seen in the docs or should i say it..... the wiki? plus recently some one posted a request for statics in the update forum and was advised to use a type with a global! did not know that functions could be nested. could lead to some pretty nasty code :D cheers. |
| ||
thats why it isn't in the docs I think ;-) wouldn't lead to a nice coding style but even worse stuff than C++ programmer already do ;) |