Local / Global Variables - Why?

BlitzMax Forums/BlitzMax Beginners Area/Local / Global Variables - Why?

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 use quite a lot of globals. Why? Because its far easier when variables are regularly needed by a range of different functions. You have two choices. Pass variables from function to function, or make them global.

For temporary variables (Such as 'For X = 1 to 10') - I would define the X as Local within a function, for instance. Reason being, I may use that variable in many different functions, but its a generic variable that I would use for many purposes.

What I DO tend to do, is have, for example, a tScore type. Within that type, I can add various fields pertaining to the game scoring system. Then at the start, all I need to do is create one tScore object, and I can access all the score variables from there. But I digress.