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

[Solved] Variable not set before reading?

L

Langsley

Guest
I have an object with a create event with the code:

var cardSelected = 0;

and then a step event in the same object with the code:

if (mouse_check_button_pressed(mb_left))
{
if(cardSelected == 0)//if card is not selected, change to selected
{
cardSelected = 1;
}
}

for some reason the step event doesn't recognize that cardSelected was set by the create event. I've tried changing the step event to a mouse click event and fudging with the self. modifier to no avail. Any help would be appreciated.
 
By using var, you've created a local variable. Its scope is limited to the event. So when the Create event ends, so does the variable.
Solution: delete var
 
Top