Cannot make the save function work in BASS template

Started by DiggingUpGraves, Fri 17/05/2024 16:05:05

Previous topic - Next topic

DiggingUpGraves

Hello, I've been trying to make the save function work for my current project set in the BASS template. I honestly don't know why it doesn't work, I'm just using the code the game came packaged with. I quickly made 2 other projects, on in SIERRA and an empty one in BASS to see if there were any differences. In SIERRA the save function works perfectly fine, but the empty BASS one doesn't work either.
Does anyone know what's going on or what I can do?


Here's the code if anyone wants to see, but it's just the one that comes out of the box.
Code: ags
int find_save_slot(String name)
{
  bool slots[] = new bool[999];
  int i = 0;

  while (i < lstSaveGamesList.ItemCount)
  {
    if (lstSaveGamesList.Items[i] == name)
    {
      // found existing save with matching name
      return lstSaveGamesList.SaveGameSlots[i];
    }

    // remember which slots are already taken
    slots[lstSaveGamesList.SaveGameSlots[i]] = true;
    i ++;
  }

  // find first free save slot, starting with slot 1
  i = 1;

  while (i < 999)
  {
    if (!slots[i])
    {
      return i;
    }

    i ++;
  }

  // no free slots found
  return -1;
}

function btnSaveGame_OnClick(GUIControl *control, MouseButton button)
{
  int gameSlotToSaveInto = find_save_slot(txtNewSaveName.Text);

  if (gameSlotToSaveInto < 0)
  {
    Display("No more free save slots!");
  }
  else
  {
    SaveGameSlot(gameSlotToSaveInto, txtNewSaveName.Text);
    close_owning_gui(control);
  }
}
function lstSaveGamesList_OnSelectionCh(GUIControl *control)
{
  txtNewSaveName.Text = lstSaveGamesList.Items[lstSaveGamesList.SelectedIndex];
}

function txtNewSaveName_OnActivate(GUIControl *control)
{
  // pressing Return in the text box simulates clicking the save button
  btnSaveGame_OnClick(control, eMouseLeft);
}

Crimson Wizard

#1
Please tell how do you expect this to work, and what exactly does not work?

Is it that gui do not appear, buttons don't trigger actions, saves are not saved, saved written into wrong slots, else? there is a lot that may happen wrong, so it's essential to be elaborate when describing the problem.


EDIT:
Also, I might mention that I recently updated BASS and Verb Coin templates to have same menu functionality as Sierra template does, maybe it will be easier to start with. The updated templates may be downloaded here:
https://github.com/adventuregamestudio/ags-templates/tree/master/Templates
Or their project source:
https://github.com/adventuregamestudio/ags-template-source

DiggingUpGraves

I've added a seperate button that opens up the Save gui, in said gui I can write the name of a save but pressing 'enter' or clicking the 'save' button does nothing. The gui just disappears and when I re-open it I see what I typed in the writing box but not as a saved slot.

But thank you already, I'll check this new version out immediately!

DiggingUpGraves

Yes! The updated template works, thank you! Still, it's weird that the previous one didn't, but I suppose that's none of my worries anymore.

Crimson Wizard

Quote from: DiggingUpGraves on Fri 17/05/2024 16:55:07I've added a seperate button that opens up the Save gui, in said gui I can write the name of a save but pressing 'enter' or clicking the 'save' button does nothing. The gui just disappears and when I re-open it I see what I typed in the writing box but not as a saved slot.

Did the save files appear in the saves folder? It's in "C:\Users\<username>\Saved Games\<your game name>"

Even if saving itself worked, maybe the existing saves were not filled in the list.

DiggingUpGraves

There seems to just be two files, a file called "agssave.999" and a zipped agssave map that says it's either corrupted or in an unknown format.

Khris

In that code, line 46 contains the command that's supposed to write the savegame file to the hard disk. You can easily debug this by simply inserting a line like Display("About to save to slot %d", gameSlotToSaveInto);

Does the message appear in game? Which slot does it show? Etc.

This is very basic debugging and absolutely something everybody should do first.

SMF spam blocked by CleanTalk