Legacy GM [SOLVED]Value not staying?

Phsyrik

Member
So I have a store in my game, and when I buy something, and come back to the store its locked again. I need to make it stay unlocked

Code:
CREATE
         global.orangelocked = 0;                                     

STEP   
        if (device_mouse_check_button(0, mb_left) && global.coincount >= 200 && global.orangelocked == 0)
        {
             global.coincount = global.coincount - 200;  
             global.orangelocked = 1;                           
             global.shiptype = 1;                                 

        }

DRAW
      if (global.orangelocked == 0)
     {
          draw_sprite(s_locked200, 0, 30, 60);
     }

     else if (global.orangelocked == 1)
     {
          draw_sprite(s_orangestore, 0, 30, 60);
     }
So when I go to a different room, and come back to rm_store the item is locked again. My guess is that its resetting the value of orangelocked to 0, but I dont know how to keep the value 1 after it has been bought.
 

Simon Gust

Member
You need to make this object persistent. It doesn't matter if it's a global variable if you are going to set it to 0 everytime this object is created because you enter the room.
 

Phsyrik

Member
You need to make this object persistent. It doesn't matter if it's a global variable if you are going to set it to 0 everytime this object is created because you enter the room.
But that makes the sprite in DRAW go from room to room as well.
 

Phsyrik

Member
oh im an idiot. Thanks Simon!

I made a separate object on the first room that set all the variables that stay persistent in the game :)
 

Simon Gust

Member
Then you need an instance that is persistent, invisible and is in charge of setting all global variables at the start of the game.
 
Top