Game module

Module for the game flow: which levels there are, and which one is being played.

Properties

  • trx.game.levels (a list of trx.game.Level). The levels of the game, in order, counted from one. (read-only)
  • trx.game.cutscenes (a list of trx.game.Level). The cutscene levels, counted from one. TR4's in-game cutscenes are a different thing, and live in trx.cutscenes. (read-only)
  • trx.game.demos (a list of trx.game.Level). The demos, counted from one. (read-only)
  • trx.game.current_level (trx.game.Level). The level being played, or nil if none is. (read-only)
  • trx.game.gym (trx.game.Level). The gym level, or nil if this game has no gym. (read-only)
  • trx.game.version (integer). Which Tomb Raider this build is: 1, 2, 3 or 4. (read-only)
  • trx.game.trx_version (string). What this build reports as its version: 1.9.3 for a release, and the tag with the commits since it for a development build. (read-only)
  • trx.game.is_loaded (boolean). Whether a level is loaded. (read-only)
  • trx.game.is_playable (boolean). Whether the game is loaded and taking input - not in a menu, and not in a cutscene. (read-only)
  • trx.game.is_ngplus (boolean). Whether this is a new game plus run, which is what the passport's bonus start sets. Lara keeps her weapons between levels and her ammunition does not run down. (read-only)

Enums

  • trx.game.LevelTable

    One of the lists of levels the game flow declares.

    • trx.game.LevelTable.TITLE = 0
      The title screen.
    • trx.game.LevelTable.MAIN = 1
      The levels of the game proper.
    • trx.game.LevelTable.CUTSCENES = 2
      The cutscenes.
    • trx.game.LevelTable.DEMOS = 3
      The demos that play when the title screen is left alone.
  • trx.game.LevelType

    What kind of level it is.

    • trx.game.LevelType.TITLE = 0
      The title screen.
    • trx.game.LevelType.NORMAL = 1
      An ordinary level.
    • trx.game.LevelType.CUTSCENE = 2
      A cutscene.
    • trx.game.LevelType.DEMO = 3
      A demo.
    • trx.game.LevelType.GYM = 4
      Lara's home, which has no level number.
    • trx.game.LevelType.BONUS = 5
      A bonus level, played once the game is finished.
    • trx.game.LevelType.DUMMY = 6
      Not a level. Kept only because old savegames refer to it.
    • trx.game.LevelType.CURRENT = 7
      Not a level. Kept only because old savegames refer to it.

Structures

  • trx.game.LevelNum

    The number a level goes by, which is what the player is shown and what a gameflow names. Not its place in a table: a level the game flow skips does not count, and a gym level has no number at all and reads 0. Counted from 1.

  • trx.game.DemoNum

    Where a demo sits in the table of demos. Counted from 1.

  • trx.game.Frames (integer)

    A length of time counted in the frames the engine runs the world at, which is what the engine measures its own timers in.

  • trx.game.Seconds (number)

    A length of time in seconds, as a player would read it off a clock.

  • trx.game.Level

    A level, as the game flow file declares it. Everything on it is read-only: a level is what the game flow says it is.

    Handles are live references: if the underlying object is destroyed, using the handle raises an error rather than silently reading an unrelated one.

    Properties:

    • key: string. What the level is called, taken from the name of the file it loads: wall.tr2 reads back as wall. Lower case, regardless of the case on disk, and nil for a level that loads no file of its own.

      This is the name to write into a table of per-level data. num is a position and moves as soon as a game flow gains a level, and path is wherever the file sits on this install. (read-only)

    • lara_outfit: string. The outfit Lara starts the level in. (read-only)

    • music_track: trx.catalog.music. The track that plays when the level starts. (read-only)

    • num: trx.game.LevelNum. (read-only)

    • path: string. Path to the level file. (read-only)

    • script_path: string. Path to the Lua script that runs when the level loads, or nil if it has none. (read-only)

    • title: string. The level's name, as shown to the player. (read-only)

    • type: trx.game.LevelType. What kind of level it is. (read-only)

    • unobtainable_ally_kills: integer. Ally kills the stats screen must not hold against the player. (read-only)

    • unobtainable_kills: integer. Kills the stats screen must not hold against the player. (read-only)

    • unobtainable_pickups: integer. Pickups the stats screen must not hold against the player, because they cannot be got. (read-only)

    • unobtainable_secrets: integer. Secrets the stats screen must not hold against the player. (read-only)

    • water_particles: boolean. Whether water particles are visible in the level's water. (read-only)

    Computed properties (derived, not stored on the object):

    • inventory: trx.inventory.Inventory. What the level keeps for Lara's return, or nil for a level that keeps nothing: the title screen and the cutscenes. It is what she will arrive there with rather than what she is carrying now, which is trx.inventory itself.
    • stats: trx.stats.Stats. What the level keeps count of, or nil for a level that counts nothing: the title screen and the cutscenes. The level being played is also trx.stats itself.

Functions

  • trx.game.play_level(level_num, [opts])
    Starts a level from trx.game.levels.

    Parameters:

    • level_num (trx.game.LevelNum).

    • opts (table, optional). How to start it.

      Keys:

      • select (boolean, optional). Start the level as the level-select screen does, rebuilding Lara's inventory to what she would carry on reaching it. Without it the level continues from the one in progress.

    Example:

    trx.game.play_level(1)
    
  • trx.game.play_cutscene(cutscene_num)
    Plays a cutscene.

    Parameters:

  • trx.game.play_demo([demo_num])
    Plays a demo, and returns the one that started.

    Parameters:

    • demo_num (trx.game.DemoNum, optional). Omit to play the next demo in rotation.

    Returns:

    • trx.game.Level or nil. The demo that started, or nil if the game has no demos.
  • trx.game.play_gym()
    Starts the gym. Raises if this game has no gym.

  • trx.game.end_level()
    Ends the current level, as though Lara had reached its exit.

  • trx.game.exit_to_title()
    Leaves the current game and returns to the title screen.

  • trx.game.exit_game()
    Closes the game.

  • trx.game.screenshot([path])
    Takes a screenshot. Without a path, writes one to the screenshots folder in the player's configured format; with a path, writes to that file.

    Parameters:

    • path (string, optional). File to write to.