Part 1 solved. Read on for part 2...
PART 1 [SOLVED]
Hello! So, I've been trying to wrap my head around this all morning but can't seem to manage.
Let's say your game saves automatically on quit.
The first time you launch the game, you have two menu options: NEW GAME or QUIT.
You select NEW GAME. You play for a while, then you QUIT.
When you re-launch the game the next day, you now have three menu options: CONTINUE, NEW GAME or QUIT. In other words, the game knows you've played before, and saved-and-quit, so pops up the option to continue from where you left off.
That's fine. I've sorted the GUIs and made the game save on quit and tied it all up, and it's lovely. The question to which I can't fathom the answer is this:
How can you check on game_start whether the game has been played before?
I'd set it up with a simple variable before but, of course, that's silly - until the game loads in the save file, the variable will be in its original state, so the game will behave as if it's being launched for the first time.
So hey, I thought, why not just load the save file automatically on start, then have the game immediately check which (if any) GUI to pop up? But no, that doesn't work either, because you can't restore save files from game_start. You just get a crash and an error.
I've looked all over the forums and the manual and tried everything I can think of. It seems like something that would be possible to do: it's a common feature in many games. It seems like the sensible option would be to simply check whether there's a file in the relevant save slot. But I just can't fathom it. Any help greatly appreciated.
UPDATE: Ah! I thought I was on to something just now with the following in game_start:
Code: AGS
...but the game crashes on launch if there's nothing in that save slot yet.
UPDATE 2: Got it! This works.
Code: AGS
PART 2
Just one tiny two-pronged problem now.
1) SaveGameSlot(); only occurs at the end of the script. So if it's on quit, the game quits before the game has chance to save itself.
2) The easy way to get around this is to just have the game save every time you pull up the menu - the player would never notice any difference. However, this means that when you load the game by pressing CONTINUE, the main menu is always left there on-screen until you get rid of it. Because the game saved when the menu was up.
And now I'm really stumped as to how to get around this issue - because I need the menu to automatically load on launch, the game to save while it's visible, but for the menu to immediately shut after loading, even if the save state includes the menu.
Any ideas at all? :/
PART 1 [SOLVED]
Hello! So, I've been trying to wrap my head around this all morning but can't seem to manage.
Let's say your game saves automatically on quit.
The first time you launch the game, you have two menu options: NEW GAME or QUIT.
You select NEW GAME. You play for a while, then you QUIT.
When you re-launch the game the next day, you now have three menu options: CONTINUE, NEW GAME or QUIT. In other words, the game knows you've played before, and saved-and-quit, so pops up the option to continue from where you left off.
That's fine. I've sorted the GUIs and made the game save on quit and tied it all up, and it's lovely. The question to which I can't fathom the answer is this:
How can you check on game_start whether the game has been played before?
I'd set it up with a simple variable before but, of course, that's silly - until the game loads in the save file, the variable will be in its original state, so the game will behave as if it's being launched for the first time.
So hey, I thought, why not just load the save file automatically on start, then have the game immediately check which (if any) GUI to pop up? But no, that doesn't work either, because you can't restore save files from game_start. You just get a crash and an error.
I've looked all over the forums and the manual and tried everything I can think of. It seems like something that would be possible to do: it's a common feature in many games. It seems like the sensible option would be to simply check whether there's a file in the relevant save slot. But I just can't fathom it. Any help greatly appreciated.
UPDATE: Ah! I thought I was on to something just now with the following in game_start:
if (Game.GetSaveSlotDescription(2) == "current save") {
gMenu2.Visible=true;
}
else {
gMenu1.Visible=true;
}
...but the game crashes on launch if there's nothing in that save slot yet.
UPDATE 2: Got it! This works.
File *output = File.Open("$SAVEGAMEDIR$/agssave.025",eFileRead);
if (output == null) {
gMenu1.Visible=true;
}
else {
gMenu2.Visible=true;
output.Close();
}
PART 2
Just one tiny two-pronged problem now.
1) SaveGameSlot(); only occurs at the end of the script. So if it's on quit, the game quits before the game has chance to save itself.
2) The easy way to get around this is to just have the game save every time you pull up the menu - the player would never notice any difference. However, this means that when you load the game by pressing CONTINUE, the main menu is always left there on-screen until you get rid of it. Because the game saved when the menu was up.
And now I'm really stumped as to how to get around this issue - because I need the menu to automatically load on launch, the game to save while it's visible, but for the menu to immediately shut after loading, even if the save state includes the menu.
Any ideas at all? :/