Hi guys i need help to make a main screen "continue" button that load the last savegame and if it's possible to autosave at certain point of the game, saving on the first avaible slot if there's no autosave, or overwriting the old one. thanks for help
It might make more sense to just reserve a slot number for autosaving... If you want to do it that way then you could seek out the first free slot like this, but note that it makes continuing from the last autosave a bit more complicated.
// GlobalScript.ash
import int autoSaveSlot;
import bool SaveSlotExists(int slot);
import int GetFirstFreeSaveSlot(int startFrom=SCR_NO_VALUE, int lastSlot=999);
import bool AutoSave();
import bool ContinueGame();
// GlobalScript.asc
int autoSaveSlot = -1;
export autoSaveSlot;
bool SaveSlotExists(int slot)
{
return (Game.GetSaveSlotDescription(slot) == null);
}
int GetFirstFreeSaveSlot(int startFrom, int lastSlot)
{
int i = 1;
if (startFrom != SCR_NO_VALUE)
{
i = startFrom;
}
if ((lastSlot < i) || (lastSlot > 999))
{
lastSlot = 999;
}
while (i < lastSlot)
{
if (!SaveSlotExists(i))
{
return i;
}
i++;
}
return -1;
}
bool AutoSave()
{
if (autoSaveSlot == -1)
{
autoSaveSlot = GetFirstFreeSaveSlot();
if (autoSaveSlot == -1)
{
return false;
}
}
SaveGameSlot(autoSaveSlot, "[AUTOSAVE]");
return true;
}
bool ContinueGame()
{
if (autoSaveSlot != -1)
{
RestoreGameSlot(autoSaveSlot);
return true;
}
int i = 0;
while (i < 999)
{
String desc = Game.GetSaveSlotDescription(i);
if (desc == "[AUTOSAVE]")
{
autoSaveSlot = i; // even though this will be overridden, this will allow you to know which slot is about to be loaded (since RestoreGameSlot is delayed)
RestoreGameSlot(autoSaveSlot);
return true;
}
i++;
}
return false;
}
thanks for reply. Reserving a slot for autosave could be fine if makes more simple the continue function.
however in both ways, I don't understand if it's possible to load the last savegame regardless it is auto or manual.