Hello everybody!
I'm trying to achieve what I think is a simple thing. I'm using AGS v3.4.0.6.
The game I'm working on has a single save slot. Whenever I hit the save button, I'd like the game to be saved at that slot and display "Game Saved!". The message will disappear after few seconds.
Then, when I restore that save, I'd like to display "Game loaded!".
In the documentation, it says that with SaveGameSlot() "The game will not be saved immediately; instead, it will be saved when the script function finishes executing".
At the moment I have this code in my GlobalScript.asc:
Overlay* myOverlay;
function repeatedly_execute_always()
{
if (IsTimerExpired(20))
{
myOverlay.Remove();
}
}
function on_key_press(eKeyCode keycode)
{
if (keycode == eKeyF5)
{
SetTimer(20, 30);
SaveGameSlot(1, "SaveGame");
myOverlay = Overlay.CreateTextual(5, 5, 150, eFontfntTiny, 65535, "Game saved!");
}
if (keycode == eKeyF6)
{
RestoreGameSlot(1);
SetTimer(20, 30);
myOverlay = Overlay.CreateTextual(5, 5, 150, eFontfntTiny, 65535, "Game loaded!");
}
}
Now, since SaveGameSlot() only saves when the script function finishes executing, where should I put the Overlay code?
At the moment, when I restore the game it still carries on the "Game saved!" overlay.
Thanks in advance! :)
By the time your restore game triggers, the following code will never be run, since when you restore a game, you aren't even at the same point in the script (you're instead at the point just after you saved).
So if you add:
on_event (EventType event, int data)
{
if (event == eEventRestoreGame)
{
SetTimer(20, 30);
myOverlay = Overlay.CreateTextual(5, 5, 150, eFontfntTiny, 65535, "Game loaded!");
}
}
It should work.
EVENTS!
Thanks a lot Scavenger! It works perfectly :)
I have never used events before and now I have definitely learned something new.