• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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