Saving to previous room[solved]

Started by Glenjamin, Mon 18/06/2018 17:33:31

Previous topic - Next topic

Glenjamin

This is my first time implementing a savegame mechanic. I checked the manual but I'm not sure what this process would be listed under.

My game has a few requirements for when you save. What would be the best way to tackle the following issues?

1. When the player loads the game, It should return them to the room they last saved in. The room should be reset. 

2. When the player dies, they get sent to the "game over" room. If you save from the game over room, the game should save the previous room, or the player will return to the game over screen on load.

3. There should only be ONE savegame slot.

How would I go about doing this? Thanks in advance.

Cassiebsg

#1
Uhm... the big question is why would anyone save the game in a "game over" room? ??? I usually just hit load or quit the game.

As for "forcing" events to be reset at loading time, then you just add the code to the "on_event" function with the eEventRestoreGame. Check the manual for more info. (nod)

As for only one slot is easy, don't give a list of options, add a button/key to save and one for loading. Then save it to the slot you decide. I normally use 99, but you can use any number you fancy (except 999, since that one of reserved for restart point).

EDIT: Oh, and if you really need the previous room, then you can use player.PreviousRoom... ;)
There are those who believe that life here began out there...

Khris

It sounds like all you need to do is disable manual saving and simply call SaveGameSlot(1); in on_event/eEventBeforeFadein. This way the one savegame always contains the current room's initial state and there's no need to reset anything in the first place. This should solve all three points.

Matti

It seems to me that you want to have manual saving but also some sort of autosave in case the player dies. Then my suggestion would be to have two savegame slots. One is used if the player saves manually, the other is saved to automatically in on_event/eEventBeforeFadein in every room like Khris described. Then when the player dies you could let them choose whether to load the autosave or the 'normal' savegame.

Glenjamin

Thanks for your help so far,

I've decided to go with Khris' method of calling SaveGameSlot(1); in eEventBeforeFadein.

The issue I'm having is the game does not carry out the eAfterFadein events. It functions perfectly when the room is first entered, but not when it's loaded.

Khris

#5
Alright, I managed to put together a workaround. It's not exactly pretty, but I don't see any other option.

Code: ags
// global header
import void afi();

// global script
void afi() {
  SaveGameSlot(1, "reset");
  SetTimer(1, 1);
}

  // add to repeatedly_execute
  if (IsTimerExpired(1)) CallRoomScript(1);


In your room script:
Code: ags
function room_AfterFadeIn() {
  afi();
}

// actual after fadein code
void on_call(int p) {
  player.Say("Room1 after fadein");  
}

(You obviously need to use a different timer / on_call index if you're already using 1.)

Instead of your AfterFadein lines, the game schedules a save and sets a timer. This 1 frame idling triggers the saving to slot #1, and right afterwards, the game calls the room's on_call(1), which runs the lines previously in AfterFadein.

Glenjamin

Thanks Khris, it works perfectly.

SMF spam blocked by CleanTalk