Legacy GM is there a difference between 'var i = 0;' and 'i = 0;'

J

JFitch

Guest
Declaring a variable with "var" makes it belong to the script calling it and not the instance calling it. This means two things:

1. Once the script is done, the variable is destroyed.
2. When using "with", you don't use "other" to access the variable. For example:

Code:
a=0;
var b=0;

with (object) {
other.a++;
b++;
}
Because the variable "b" was declared using "var" and the variable "a" was not, "a" is accessed in the "with" function using "other" and "b" is not.
 
Top