GameMaker Saving Character progression between rooms [SOLVED]

J

jiminy123

Guest
I am current a few days into making my first project. I have set up a basic top down rpg where the character can lv up increasing stats. I am coming to adding my second room. How do I save the character progress between rooms. at the moment when I go to the next room it resets the character back to lv one.

I have tried looking for guides and cant find any. Can anyone help me out or point me in the of a guide for this?
 

The-any-Key

Member
You need to keep the stats. There are many ways you can do this. Ex make the player object persistent. Then the player instance will still exists when you go to another room. Or use a persistent control instance that keeps the values that the new player instance in the room grab.
 

samspade

Member
It's probably not the best method, but here's how I do it. Player stats are stored in global variables. I have a save script and a set script So for example:

Code:
///scr_save_player_variables();
global.hp = hp;
global.level = level;

///scr_set_player_variables();
hp = global.hp;
level = global.level;

/////example use

///whatever creates the player object
with (instance_create_layer(x, y, layer, obj_player)) {
    scr_set_player_variables();
}


///player destroy or code
scr_save_player_variables();
Depending upon how the rest of your project is set up, you'd have to change the above example to fit. Note that both scripts assume you are calling them from within the obj_player object. But it's easy to code around that if you aren't. Also note that this method requires you to be certain to save variables correctly.

Since I reference a lot of the player variables in the player object themselves, I think it is faster for my project to have duplicate variables one set of global and one set of instance variables. But if you don't have that many it may be easier to just have global variables or a persistent object that both holds and uses the variables directly, rather than as a method of saving between room changes.
 

Slyddar

Member
You need to keep the stats. There are many ways you can do this. Ex make the player object persistent. Then the player instance will still exists when you go to another room. Or use a persistent control instance that keeps the values that the new player instance in the room grab.
Just to follow up on this for the OP, if you make an object persistent, it means it will now always be carried through to all future rooms. You need to be aware that creating the object by dragging it into the room editor, will create multiple versions of the object, if you allow the player to move back and forth between rooms. It's the easiest way to store stats like you are asking for, but just ensure you have another object, or the first rooms creation code, create the player object after first checking it does not exist, if you allow room to room travel. You'll then want a way to place the player in the next room, but there are tutorials around for traveling between room.
 
Last edited:
J

jiminy123

Guest
Thanks guys, I have just made a persisent object for the characters stats and deleted them from the original and it all seems to be working now.
Thanks to all the replies :)
 
Top