How to SAVE the game? SOLVED

Started by Caracal, Mon 04/11/2013 10:18:39

Previous topic - Next topic

Caracal

Hello everybody, after a long time I finally come up with another issue.

This time I cannot save the game while playing.
The Save GUI shows and lets me write the filename and everything seems perfect, but it appears that It does not create a save-file.

The manual does not seem to give any information about the regular save (only the advanced save functions).
Saving is essential since my game is going to be a long lasting experience! ;-)

Hoping for help and thank you in advance!

Khris

Are you using the default game? A template? Have you changed anything about the process? Does the game actually call SaveGameSlot()?
How do you figure the game isn't saved? Do the save games not appear in the restore dialog's list?
Have you looked in the save game directory? c:\Users\user name\Saved Gamed\game name\

Caracal

#2
Hy Khris!
I did base my game on a default game. And I cared not to change anything on the basics.
The thing is that the game will not appear in the restore dialogue box.
The code for the “Save” button is as follows:

Code: ags

function btnSaveGame_OnClick(GUIControl *control, MouseButton button)
{
  int gameSlotToSaveInto = lstSaveGamesList.ItemCount + 1;
  int i = 0;
  while (i < lstSaveGamesList.ItemCount)
  {
    if (lstSaveGamesList.Items[i] == txtNewSaveName.Text)
    {
      gameSlotToSaveInto = lstSaveGamesList.SaveGameSlots[i];
    }
    i++;
  }
  SaveGameSlot(gameSlotToSaveInto, txtNewSaveName.Text);
  close_save_game_dialog();
}


The only times I tried around with the save options is through the general settings panel… (advanced save ect.)
I just found out that the files are being saved in (User/Username/Savedgames...) But to no avail. The game does still not respond to them.

Khris

So you're saying that the save games do appear in the folder, they are just not displayed in the restore dialog?

In other words, saving the game works perfectly fine, but you aren't filling the listbox with the savegames.

This is the function that is called in a default game:
Code: ags
function show_restore_game_dialog()
{
  gRestoreGame.Visible = true;
  lstRestoreGamesList.FillSaveGameList();
  mouse.UseModeGraphic(eModePointer);
  gIconbar.Visible = false;
}

Note the fourth line.
I suspect you're merely turning the restore GUI to visible, which will of course cause the list of save games to remain blank.

Caracal

The function in my game looks like this:
Code: ags
function show_restore_game_dialog()
{
  gRestoreGame.Visible = true;
  lstRestoreGamesList.FillSaveGameList();
  mouse.UseModeGraphic(eModePointer);
  
}

I cant see any meaningful difference to the default.

Khris

But you are calling this function, right?
Because even if you have that function in your script, it needs to be called for it to work.

How does your game show the restore dialog?
If you use
Code: ags
function show_restore_game_dialog()
{
  gRestoreGame.Visible = true;
  lstRestoreGamesList.FillSaveGameList();
  Display("Savegame list filled.");
  mouse.UseModeGraphic(eModePointer);
}

does it show the message?

Also make sure it's not something simple like the listbox text having the same color as the background.

Caracal

It still shows nothing.
Even when i copy this funtion in there, it does not work.
I checked the colors... thats not it!

Khris

Do you see the message "Savegame list filled." ?

What happens if you start a new default game? Does it let you restore a save game?

Caracal

Ok i have started a new game. And the Save-Load function did in fact work!
Then I have copied and pasted the functions and put them into my game,… but that did not change anything.
I can still not see anything in the load-panel.
The Loading function in my game looks like this: (when I press the “Load button”)
Code: ags

function btnRestoreGame_OnClick(GUIControl *control, MouseButton button)
{
  if (lstRestoreGamesList.SelectedIndex >= 0)
  {
    RestoreGameSlot(lstRestoreGamesList.SaveGameSlots[lstRestoreGamesList.SelectedIndex]);
  }
  close_restore_game_dialog();
  aMainTheme.Stop();
    gInventory.Visible = true;
    gInventorySchno.Visible = true;
}
 

As you can see I just added some commands at the end of the function. That is all I ever did with it… I never even touched it before, because I feared the situation I am in right now!
The save function looks like this: (when I press the save button)
Code: ags

function btnSaveGame_OnClick(GUIControl *control, MouseButton button)
{
  int gameSlotToSaveInto = lstSaveGamesList.ItemCount + 1;
  int i = 0;
  while (i < lstSaveGamesList.ItemCount)
  {
    if (lstSaveGamesList.Items[i] == txtNewSaveName.Text)
    {
      gameSlotToSaveInto = lstSaveGamesList.SaveGameSlots[i];
    }
    i++;
  }
  SaveGameSlot(gameSlotToSaveInto, txtNewSaveName.Text);
  close_save_game_dialog();
}
 

Khris

#9
Both these functions don't really matter with respect to the issue; since the list of save games remains blank, the first one will get called with SelectedIndex being -1. (Also, I'm pretty sure that the commands you added are pointless, since they are executed before the save game is loaded, which then overrides their effect anyway. To do stuff after a game has been restored, use eEventRestoreGame in on_event.)
The second one is about saving the game, and we have already established that saving works, since you said you can see save game files in the relevant folder.

@ Anybody else reading this:
It should also be noted that Caracal sent me the source files, and restoring the game worked for me; I could see the save games I created just fine in the listbox.


Edit:
Never mind, I have figured out the problem.
The funny / sad thing is that the problem was right what I suspected it to be from my second reply on forward. The error is in fact precisely what I suggested right in there...

I tested restoring a game by pressing F7. This calls the function show_restore_game_dialog() and thus works fine.
What you did was use the button on the panel though. This button will clean up, then call the OnClick handler of the load button in the IconBar, at least in a Default Game. In your game there's no IconBar though, and so you edited the function. And what does it do instead of calling show_restore_game_dialog()? It simply sets the GUI to being visible, which means the ListBox never gets filled.

Caracal

This is it!
Thank you very mutch!

SMF spam blocked by CleanTalk