Skip to main content

Game

The game library provides useful functions for interacting with the game. This includes saving and loading, starting/stopping demo recording, getting the game directory, pausing, and launching "async" tasks.

Example

portal/lua/scripts/game_example.lua
game.save("test-save")

game.load("test-save")

console.msg("Game Directory: %s", game.get_directory())

Documentation


game.save(name)

Saves the game with the specified name.

Parameters

  • name (string): The name of the save.

Example

game.save("MySave")

game.load(name)

Loads a saved game with the specified name.

Parameters

  • name (string): The name of the save to load.

Example

game.load("MySave")

game.start_recording(name)

Starts recording a demo with the specified name.

Parameters

  • name (string): The name of the demo.

Example

game.start_recording("MyDemo")

game.stop_recording()

Stops recording the current demo.

Example

game.stop_recording()

game.pause()

Pauses the game.

Example

game.pause()

game.unpause()

Unpauses the game.

Example

game.unpause()

game.is_paused()

Checks if the game is currently paused.

Returns

  • boolean: true if the game is paused, false otherwise.

Example

local paused = game.is_paused()

game.get_client_tick()

Returns the current client tick.

Returns

  • number: The current client tick.

Example

local clientTick = game.get_client_tick()

game.get_server_tick()

Returns the current server tick.

Returns

  • number: The current server tick.

Example

local serverTick = game.get_server_tick()

game.get_directory()

Returns the game directory.

Returns

  • string: The game directory.

Example

local directory = game.get_directory()

game.async(callback)

Launches an asynchronous task that runs the callback in a new thread.

Parameters

  • callback (function): The callback function to run asynchronously.

Returns

  • thread|any: The thread that is running the callback.

Example

local asyncThread = game.async(function()
-- Perform asynchronous task here
end)