• 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 Problem with variables in persistent object

Hi, I've created an object to handle a number of variables within my game, e.g. score and hp. The variables are within the object's create event. I'd like the object to be persistent across the game, but when I mark it as persistent it stops functioning correctly. For example, my variable 'killscore' increments by one every time the player kills a monster. This works fine until I check the object's persistent tick box. Then the killscore variable behaves inconsistently, sometimes going up by 1, sometimes by 2.

Any ideas would be really appreciated. Cheers.
 

chamaeleon

Member
Hi, I've created an object to handle a number of variables within my game, e.g. score and hp. The variables are within the object's create event. I'd like the object to be persistent across the game, but when I mark it as persistent it stops functioning correctly. For example, my variable 'killscore' increments by one every time the player kills a monster. This works fine until I check the object's persistent tick box. Then the killscore variable behaves inconsistently, sometimes going up by 1, sometimes by 2.

Any ideas would be really appreciated. Cheers.
Show some code that modify killscore and other pertinent snippets? Do you by any chance move between rooms, ending up in the same room more than once, and getting a persistent object created more than once?
 
That was it - I'd created the persistent object more than once. It was in the title screen and then I had a different instance of the same object in the first level of the game. Thanks for getting back chamaeleon, your questions got me looking in the right area.
 

kburkhart84

Firehammer Games
Good you got it fixed...the usual way many of us handle objects like that is by having a single room that has them, and then just goes straight to the next room, and is never visited again. Another way in case you want to put instances in all the rooms so it doesn't matter what order they are in is to have it in the create event see if there is another such instance and destroy itself if there already is.

Last thing to consider, global variables are there for a reason, and in some cases are an easy solution. If you are doing anything besides the basics with the data, such as saving it to files to reload later, etc... then you may want to keep it on an object as it is now, but sometimes simple global variables are enough.
 
Top