How important are local variables?

I seam to have not used locals at all, just so I can call them from other functions. Is that a bad habit?

its bad for memory heavy games(lots of objects)

So what's the problem with local variables? You can call them from other functions just as easily. The only situation I can think of where you can't access a local variable is when you create it inside a function/module and then try to access it outside that function/module. But creating a global inside a function is a very bad idea.

By using only globals you actually produce spaghetti code and make it harder for yourself to maintain the program as it grows in size. The more modular and independent pieces of your code are, the better.

I will attempt to use locals more then :)

Local variables make your code faster, generally.

Here's a great post on locals as well as some good comments too.

There is an alternative article where I have tried to explain how variables work and are assigned in memory. So you can have a look, if you are interested here and here .

cheers,

?:)

views:1539 update:2011/10/5 8:48:05
corona forums © 2003-2011