Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: magintz on Sat 01/05/2010 11:58:28

Title: on_event restoregame display message (SOLVED)
Post by: magintz on Sat 01/05/2010 11:58:28
Hi peoples. Just trying to put in a message that says "game loaded" upon the restoration of a saved game, here's my code:

function on_event (EventType event, int data)
{
if(event == eEventRestoreGame) {
Display("Game Loaded.");
}
}


However I'm assuming the code is running before the fade in is complete as the screen remains black until I click the mouse and the game fades in, sans message.

Any idea if I'm doing something wrong or is there a way of getting it to work.

I've tried adding a fadeIn(3) before the display, which shows the room background but again no display message and there is no cursor or GUI until I click the mouse.
Title: Re: on_event restoregame display message
Post by: Wyz on Sat 01/05/2010 14:21:56
A quick hack to do this would be to have a global variable that tells the game was loaded from a save game. Then you could check for that value in the 'Player enters room after fadein' event. There is no global event for this as far as I know, so you should check for it in each room separately in that case.

Global script headerimport LoadedGame;

Global scriptbool LoadedGame = false;
export LoadedGame;

function on_event (EventType event, int data)
{
    if (event == eEventRestoreGame)
        LoadedGame = true;
}


Each room
function room_AfterFadeIn()
{
    if (LoadedGame)
    {
        LoadedGame = false;
        Display("Game Loaded.");
    }
}


It is a bit dirty, maybe that someone else can think of something more sophisticated. :)
Title: Re: on_event restoregame display message
Post by: magintz on Sat 01/05/2010 16:21:20
Thanks. Although it's a solution I'd much rather avoid. I'll wait and see f anyone else has any ideas.
Title: Re: on_event restoregame display message
Post by: magintz on Tue 04/05/2010 19:36:37
Here's my global solution:


// At the top of the global scripts file
bool restored = false;

// Global on_event
function on_event (EventType event, int data) {
if(event == eEventRestoreGame) {
restored = true;
}
}

// Global repeatedly_execute
function repeatedly_execute() {
if(restored) {
restored = false;
Display("Game Restored.");
}
}


Works a treat!
Title: Re: on_event restoregame display message (SOLVED)
Post by: monkey0506 on Wed 05/05/2010 00:31:18
Granted it's not strictly optimal to have to hook your events this way across multiple functions (in this case only two of course), but yes, that solution seems appropriate. :=

P.S. Does this mean you accept what I said in the beta thread? :P
Title: Re: on_event restoregame display message (SOLVED)
Post by: magintz on Thu 06/05/2010 21:27:27
Quote from: monkey_05_06 on Wed 05/05/2010 00:31:18
P.S. Does this mean you accept what I said in the beta thread? :P

Indeed :)