Quote:
Originally Posted by xAndrewx
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.