on_event restoregame display message (SOLVED)

Started by magintz, Sat 01/05/2010 11:58:28

Previous topic - Next topic

magintz

Hi peoples. Just trying to put in a message that says "game loaded" upon the restoration of a saved game, here's my code:

Code: ags
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.
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

Wyz

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 header
Code: ags
import LoadedGame;


Global script
Code: ags
bool LoadedGame = false;
export LoadedGame;

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


Each room
Code: ags

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. :)
Life is like an adventure without the pixel hunts.

magintz

Thanks. Although it's a solution I'd much rather avoid. I'll wait and see f anyone else has any ideas.
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

magintz

Here's my global solution:

Code: ags

// 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!
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

monkey0506

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

magintz

When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

SMF spam blocked by CleanTalk