GML var question

mizzy

Member
Hello Happy Game Makers,

I have a very noob question for you (was unable to find on my own):

When I declare a variable.. do I have to write var before it?
ex:
var thingy = 0;
or can i just write:
thingy = 0;

as far as I can tell they do the same thing, but I am very early on in my project (GMS2) and I don't want to shoot myself in the foot if it can be helped :)
thanks!
 
No var means the variable is temporary scope and only stays valid for the currently executing event/script/statement. If you type var before a variable in the Create Event, that variable will not be valid in the Step Event, for instance. There's a big difference between the two. Look up variables and scope to read more about it.
 

mizzy

Member
No var means the variable is temporary scope and only stays valid for the currently executing event/script/statement. In any case, there's a big difference between the two. Look up variables and scope to read more about it.
awesome! Will do, thanks!
 
Top