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.
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.
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"
end
I had a similar question and yall helped. A further thing Im wondering is, how to pick the x,y in the varRoomLocation.
Like how do I get the player to be in the exact same position they were last in, in addition to the last room. Or even guarantee a safe position without having to design every room with a safe tile?
I have a script for an RPG where I need to remember the room and location before going to the battle screen. I did it like this:
on collect do
randEncounter = random 1,30
if randEncounter>=29 then
returnX = event.px
returnY = event.py
returnRoom = event.room
battleNum = random 1,2
say "B-B-B-BATTLE!!!"
goto 18,7 in "battle"
end
end
You would have to store that information with "store" and then recalling it with something like
on load do
restore
end
in the script for the Game. I haven't yet gotten to it with saving position and reloading, but it has worked with other variables so it shouldn't be any different.
As far as items go, you can put in specific checks for each one, which becomes a lot of code if there are a lot of items. Someone else will probably have a better way to solve this. But that's what I've been doing.