Table Logic

Saving data, triggering functions, and callbacks for level-specific scripts.

Special objects

Lara A Objects.Moveable representing Lara herself.

Special tables

LevelVars A table with level-specific data which will be saved and loaded.
GameVars A table with game data which will be saved and loaded.
LevelFuncs A table with level-specific functions.


Special objects

Lara
A Objects.Moveable representing Lara herself.

Special tables

TombEngine uses the following tables for specific things.
LevelVars
A table with level-specific data which will be saved and loaded. This is for level-specific information that you want to store in saved games.

For example, you may have a level with a custom puzzle where Lara has to kill exactly seven enemies to open a door to a secret. You could use the following line each time an enemy is killed:

LevelVars.enemiesKilled = LevelVars.enemiesKilled + 1

If the player saves the level after killing three, saves, and then reloads the save some time later, the values 3 will be put back into LevelVars.enemiesKilled.

This table is emptied when a level is finished. If the player needs to be able to return to the level (like in the Karnak and Alexandria levels in The Last Revelation), you will need to use the GameVars table, below.

GameVars
A table with game data which will be saved and loaded. This is for information not specific to any level, but which concerns your whole levelset or game, that you want to store in saved games.

For example, you may wish to have a final boss say a specific voice line based on a choice the player made in a previous level. In the level with the choice, you could write:

GameVars.playerSnoopedInDrawers = true

And in the script file for the level with the boss, you could write:

if GameVars.playerSnoopedInDrawers then
    PlayAudioTrack("how_dare_you.wav")
end

Unlike LevelVars, this table will remain intact for the entirety of the game.

LevelFuncs

A table with level-specific functions.

This serves two purposes: it holds the level callbacks (listed below) as well as any trigger functions you might have specified. For example, if you give a trigger a Lua name of "my_trigger" in Tomb Editor, you will have to implement it as a member of this table:

LevelFuncs.my_trigger = function()
    -- implementation goes here
end

The following are the level callbacks. They are optional; if your level has no special behaviour for a particular scenario, you do not need to implement the function. For example, if your level does not need any special initialisation when it is loaded, you can just leave out LevelFuncs.OnStart.

The order of loading is as follows:

  1. The level data itself is loaded.
  2. The level script itself is run (i.e. any code you put outside the LevelFuncs callbacks is executed).
  3. Save data is loaded, if saving from a saved game (will empty LevelVars and GameVars and repopulate them with what they contained when the game was saved).
  4. If loading from a save, OnLoaded will be called. Otherwise, OnStart will be called.
  5. The control loop, in which OnControlPhase will be called once per frame, begins.

Fields:

  • OnStart function Will be called when a level is entered by completing a previous level or by selecting it in the menu. Will not be called when loaded from a saved game.
  • OnLoad function Will be called when a saved game is loaded
  • OnControlPhase function(float) Will be called during the game's update loop, and provides the delta time (a float representing game time since last call) via its argument.
  • OnSave function Will be called when the player saves the game
  • OnEnd function Will be called when leaving a level. This includes finishing it, exiting to the menu, or loading a save in a different level.
generated by LDoc 1.4.6 Last updated 2022-08-11 22:43:52