Globals

Blitz3D Forums/Blitz3D Beginners Area/Globals

Paulo(Posted 2005) [#1]
Hi all,

I get the impression that using variables locally is the best approach, but why is this? Personally I find it much more difficult to approach the code this way and find that blatant use of Globals takes the head ache out of loading stuff up, etc. What point am I missing, if at all? It just seems to me better to have something available at any point of your code than not, but Im a novice, so... :)

Cheers,
Paulo


RiverRatt(Posted 2005) [#2]
Locals are better because when using them in functions you can create reusable code. Code that is independent of the rest of your code so if you write a function once you never have to write it again, and you can use it in different games. Also I have found locals better because you can use the same variable name over and over for different things in the same game.Try that with globals and your variables will get scrambled. Another thing is that using local makes it easier to reload your game from a start screen.


HappyCat(Posted 2005) [#3]
Both are as valid as each other. If a value is only needed within a function then use a Local, but if the value is needed globally then just use a Global and don't worry too much about it :-)


Paulo(Posted 2005) [#4]
Thanks for the input guys, I'll not worry about it :)