Help with player position save

Hello again. I'm having trouble figuring out how to save a player's position upon entering and leaving the game. For example, in my case, I enter through a title screen to begin the game and start in a room. But if I move to a new room and then leave the game, upon re-entry the character spawns in the new room.

That's what I'm trying to figure out at the moment.


1 Like

Did you get a solution yet?

What you're going to want to do is use the store and restore PulpScript functions.

Whenever you change rooms, for example during on enter do event, you will want to save the player's location to a variable for persistent storage:
store "varRoomLocation"

Before leaving the game, this information needs to be actually put into persistent storage. This happens when you change rooms or call an ending. So you'll have to make sure one of those 2 things happen before the player quits, otherwise it doesn't actually save it.

Upon loading the game, you will need to call the restore function. You could do this in the game script's on load do. This should now load the saved "varRoomLocation" into your current "varRoomLocation" variable. At that point, you need to send the player to that room. Such as goto x,y in varRoomLocation

This is just one way of handling it, but the important part is the store/restore pair of functions.


Thanks for responding.

I just tried this and it worked! Is there a way to do this in more than one room?

Yeah. You could just set the "varRoomLocation" in every room within its on enter do script, but with a different room name each time. I don't think there's a built-in function for retrieving the current room's name, so you have to set it manually in PulpScript.

on enter do
     varRoomLocation = "NewRoom Name"
     store "varRoomLocation"
1 Like

You can use to get the current room name. From the docs:

"In every event except load , its room member set to the name of the current room."


Oh, cool. Thanks orkn.

So then I guess I would do this once inside the player script perhaps, instead of in every room.

on update do
     varRoomLocation =
     store "varRoomLocation"
1 Like