Variable scope

BlitzMax Forums/BlitzMax Programming/Variable scope

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

Since bozoTheClown is defined as local within function foo, it really becomes global within the scope of foo.

It's local within the scope of foo since it's declared as local (which, in BlitzMax, means that it can only be seen at the level declared, neither higher nor lower). If you want it global within foo (so that it can be seen at lower, but not higher, scope levels), then declare it as such, and there's no problem:

Strict

Function foo()
	Global bozoTheClown:Int
	
	Function bar()
		bozoTheClown=10
	End Function

End Function 

foo
Incidentally, this makes it static within foo as well. If that's undesirable, then go ahead and declare it local and just pass it to bar as a parameter (I personally prefer that approach to make coupling obvious).

Yeah, Pascal's scope rules rock, but BlitzMax's are quite serviceable. And think of all the semicolons you're saving! ;)