View Single Post
  #12  
Old 06-04-2007, 09:48 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by xAndrewx View Post
Yes you do, else it's stored.
Wrong, if you'd notice in the first set of code I declare the temp variables before the actual script, this means that those variables are now temp and can be referenced without temp. and they will still be cleared after the function has ended.

If referencing a variable without the prefix meant its global than why can you reference static variables, most notably in GUI Controls, without the prefix and have them not be global variables?

When you reference a variable without the prefix, the engine first looks for a temp variable with the variable name, if it can't find that it will then look for a static (built-in) variable of the current object (this.), and if it can't find that either it defaults to global.

Function parameters are automatically declared temp so you don't need to bother with that, any other temp variables you can declare them to 0 at the beginning of the function for readability.

Declaring a temp variable to zero initializes it for the duration of the function so the engine will find it before going global.
__________________

Last edited by Inverness; 06-04-2007 at 10:01 PM..
Reply With Quote