Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: TheMagician on Thu 27/04/2006 16:41:54

Title: How to check if game has ended?
Post by: TheMagician on Thu 27/04/2006 16:41:54
Hi everybody,

I honestly didn't find anything in the manual or here in the forum, probably because it is so easy:

How can I check if the game has ended?

I need that for my script module to delete the dynamic sprites at the end of the game.

Many thanks in advance,
Stefan
Title: Re: How to check if game has ended?
Post by: Ashen on Thu 27/04/2006 16:55:02
This has been asked before (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=24070.0) (sort of - it's a similar question, anyway).

I think the current solution is - since the user can control how the player can exit the game (GUI button, keypress, etc) they can just call the delete functions there too. For a module, you'll need to create a function they can call which deletes all Dynamic Sprites created by that module, e.g.:

MyMod.End();
QuitGame(0);


At least until the eEventQuitGame value is added.
Title: Re: How to check if game has ended?
Post by: strazer on Thu 27/04/2006 16:59:16
Aside from the warning messages you get, can someone explain to me why dynamic sprites have to be deleted at all when the game is quit? Won't they automatically be freed from memory when the AGS engine shuts down?
Title: Re: How to check if game has ended?
Post by: TheMagician on Thu 27/04/2006 18:55:03
@Ashen:
Yes, that's the solution I came up with, too.

@strazer:
You are the expert  ;) The only thing I know from my tests is that there's always a warning message generated after I quit the game.

So let's all hope for a eEventQuitGame;
Title: Re: How to check if game has ended?
Post by: Scorpiorus on Sun 30/04/2006 01:48:21
Quote from: strazer on Thu 27/04/2006 16:59:16
Aside from the warning messages you get, can someone explain to me why dynamic sprites have to be deleted at all when the game is quit? Won't they automatically be freed from memory when the AGS engine shuts down?

Yeah, I'm more then certain the engine does free it all on quit.


The new-style Strings for instance; if you declare a global String variable, it's really a null-pointer until you set an actual text to it. And it will be silently discarded whenever you quit a game.

It's just a good practice to free resources explicitly, if it's you who allocated them in the first place -- hence a warning message if you don't. And it's in fact "a must" in some other environments :)