Jump to content


Photo

Variables being reset everytime the room is entered


Best Answer TsukaYuriko, 28 March 2016 - 08:56 PM

Alarms are local to instances, and instances are local to the room they were created in unless you flag them as persistent (otherwise they are destroyed at room end).

 

You'll either have to flag the object that has the alarms as persistent or make your own global alarm system.

Go to the full post


  • Please log in to reply
4 replies to this topic

#1 love4420

love4420

    GMC Member

  • New Member
  • 18 posts
  • Version:GM:Studio

Posted 28 March 2016 - 08:38 PM

Hi! So, I have a game with health bars. The syntax to set variables for the health bars looks like this:

///Variables/Alarms
global.happy = 100;
global.thirst = 100;
global.hunger = 100;
global.hp = 100;

global.maxhappy = 100;
global.maxthirst = 100;
global.maxhunger = 100;
global.maxhp = 100;

//Decrease Variables
alarm[0] = 50;
alarm[1] = 75;
alarm[2] = 75;

That is in a create event. My health bars work great. They are in room A. When I leave Room A and go to Room B, and then come back to Room A, the variables are all reset back to 100. How do I avoid this? I tried putting it in a game start event, and it came up with an error since the alarms use the variables before the game start can set them. I tried putting it in an object that goes in the room before (like a setup room) and that didn't work because the alarms are in a different object. 

 

Any suggestions? Sorry if the answer is obvious, I'm still new  ^_^


  • 0

:lol:


#2 TsukaYuriko

TsukaYuriko

    Remember... and never forget

  • Global Moderators
  • 9535 posts
  • Version:GM:Studio

Posted 28 March 2016 - 08:42 PM

The approach you tried is the one you want to go with. Make sure that you leave the alarm code where it currently is, though - that's where it belongs.


  • 0

yBGBXQa.pngmWOQbeq.png


#3 love4420

love4420

    GMC Member

  • New Member
  • 18 posts
  • Version:GM:Studio

Posted 28 March 2016 - 08:49 PM

Okay, so I put the variables in another object in the setup room and that worked well, I left the alarm stuff in the create event. Now, whenever I leave the room, the alarms are all set back again. Also, they pause whenever I'm in Room B and resume once I go back to Room A after the alarms are all reset


  • 0

:lol:


#4 TsukaYuriko

TsukaYuriko

    Remember... and never forget

  • Global Moderators
  • 9535 posts
  • Version:GM:Studio

Posted 28 March 2016 - 08:56 PM   Best Answer

Alarms are local to instances, and instances are local to the room they were created in unless you flag them as persistent (otherwise they are destroyed at room end).

 

You'll either have to flag the object that has the alarms as persistent or make your own global alarm system.


  • 0

yBGBXQa.pngmWOQbeq.png


#5 love4420

love4420

    GMC Member

  • New Member
  • 18 posts
  • Version:GM:Studio

Posted 28 March 2016 - 09:10 PM

Duh, I should've made it persistent in the first place  :wallbash: 

thank you!  :lol:


  • 0

:lol: