• 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!

Where to put instance variable so it is set before being read

J

jana

Guest
I'm getting an error, saying that a variable in an object's collision event is not set before being read. I declared the variable in the object's create event:
Code:
var vib = 0;
I want each instance to have it's own copy of this variable that will be updated every time the object is involved in a collision.

Here's the error:
############################################################################################
FATAL ERROR in
action number 1
of Step Eventobj_player
for object obj_eOrb:

Variable obj_eOrb.vib(100002, -2147483648) not set before reading it.
at gml_Object_obj_eOrb_CollisionEvent_4_1 (line 1) - vib += 1;
############################################################################################
Where else would I put an instance variable besides the object's create event if I need it stick around so it can be updated throughout the game?
 

FrostyCat

Redemption Seeker
Get rid of that var, then read up on when you should be using it and when you shouldn't be. Way too many novices these days could spend days watching videos, yet refuse to spare a few seconds learning when to use var and when not to.

And this one sentence is what I mean by a few seconds: If the variable will be used in a later event anywhere else, don't use var.
 
J

jana

Guest
Get rid of that var, then read up on when you should be using it and when you shouldn't be. Way too many novices these days could spend days watching videos, yet refuse to spare a few seconds learning when to use var and when not to.

And this one sentence is what I mean by a few seconds: If the variable will be used in a later event anywhere else, don't use var.
Got it, thank you. I actually see now that var is for very short-term variables (like just for an event action or for a script) that don't need to remain in the game. I'm used to C-style languages, so I automatically want to put some kind of "type" in front of a variable name.
 
Top