Manage save slots and saved games.
Which set of save slots a slot belongs to.
trx.savegame.Pool.NORMALtrx.savegame.Pool.QUICKSlot number within the pool. For the quick pool this is the on-screen order. Counted from 1.
What a slot holds, as the save list shows it.
Properties:
can_restart: boolean. Whether the level can be restarted from the save.can_select_level: boolean. Whether the save reaches an earlier level in the game.counter: integer. The save count when this save was written.has_story: boolean. Whether story content runs before the saved level.is_quick: boolean. Whether the save is a quick save.level_num: integer. Where the level sits in the main level table.level_title: string. The name of the level the save was made in.saved_at: table, optional. When the save was made, in the player's local time, or nil for a save that does not record it.trx.savegame.set_save_offer([check])
Decides whether the game offers a save as a level ends. The statistics
screen makes the offer before it ends, as trx.ui.StatsContext.offers_save
tells it, and a save made there resumes after the statistics, so loading it
goes on to whatever follows the level. Without a check, the game offers no
save.
The check is asked only where another level follows the statistics. Set it from the game script: it stays set until it is replaced or cleared, whichever level is being played.
Parameters:
check (function, optional). The function to ask. It is handed the level that ended, and returns whether to offer a save. Omit it to offer none.
Called with:level (trx.game.Level). The level whose statistics closed.Example:
trx.savegame.set_save_offer(function(level)
return level.type == trx.game.LevelType.NORMAL
end)
trx.savegame.slot_count([pool])
Counts the slots in a pool.
The quick pool counts only slots that hold a save.
Parameters:
pool (trx.savegame.Pool, optional). Which set of slots to look in. Defaults to NORMAL.Returns: integer. The number of slots.
trx.savegame.is_free(slot_num, [pool])
Whether a slot holds no save.
Parameters:
slot_num (trx.savegame.SlotNum).pool (trx.savegame.Pool, optional). Which set of slots to look in. Defaults to NORMAL.Returns: boolean. Whether the slot is empty.
trx.savegame.load(slot_num, [pool])
Starts the saved game in a slot.
The game flow loads it after this call returns. Raises when the slot holds no save.
Parameters:
slot_num (trx.savegame.SlotNum).pool (trx.savegame.Pool, optional). Which set of slots to look in. Defaults to NORMAL.Example:
trx.savegame.load(1)
trx.savegame.save([slot_num], [pool])
Writes a saved game to a slot.
A quick save without a slot number uses the next slot in the rotation. Otherwise, it uses the named slot.
Parameters:
slot_num (trx.savegame.SlotNum, optional). The quick pool uses the next slot in its rotation when it is omitted.pool (trx.savegame.Pool, optional). Which set of slots to look in. Defaults to NORMAL.Returns: boolean. Whether the save was written. false means that the quick pool had no slot.
Example:
trx.savegame.save(1)
trx.savegame.info(slot_num, [pool])
Returns the slot contents, or nil if the slot is empty.
Parameters:
slot_num (trx.savegame.SlotNum).pool (trx.savegame.Pool, optional). Which set of slots to look in. Defaults to NORMAL.Returns: trx.savegame.SlotInfo or nil. What the slot holds.
Example:
local info = trx.savegame.info(1)
if info ~= nil then
trx.log.info(info.level_title)
end
trx.savegame.delete(slot_num, [pool])
Removes the save from a slot and deletes its file.
Parameters:
slot_num (trx.savegame.SlotNum).pool (trx.savegame.Pool, optional). Which set of slots to look in. Defaults to NORMAL.Returns: boolean. Whether a save was removed.
trx.savegame.total_count()
Counts the saves in every pool.
Returns: integer. The number of saves.
trx.savegame.restart_available([slot_num], [pool])
Reports whether the saved level can be restarted.
With no slot, this uses the save the game is running from. A game that is not running from a save can always restart.
Parameters:
slot_num (trx.savegame.SlotNum, optional). The slot to ask about. The running save answers when it is omitted.pool (trx.savegame.Pool, optional). Which set of slots to look in. Defaults to NORMAL.Returns: boolean. Whether the level can be restarted.
trx.savegame.reached_levels(slot_num, [pool])
Returns the levels up to the saved one without starting it.
Parameters:
slot_num (trx.savegame.SlotNum).pool (trx.savegame.Pool, optional). Which set of slots to look in. Defaults to NORMAL.Returns: a list of trx.game.LevelNum or nil. The levels, or nil when the slot holds no save that can be read.
trx.savegame.play_story(slot_num, [pool])
Plays the story content that runs before the saved level.
Raises when the slot holds no save, or when no story runs before it.
Parameters:
slot_num (trx.savegame.SlotNum).pool (trx.savegame.Pool, optional). Which set of slots to look in. Defaults to NORMAL.trx.savegame.recent_slot()
Returns the slot where a save list should open.
This is the slot that the game last loaded or saved. If there is no such slot, it is the most recently written save, and then the first numbered slot.
Returns:
nil. The slot number, or nil where the game keeps no slots.