game

The game's state: stage, hunt, version, screen, messages.

Functions

# game.stage() → string

Which screen the game is on.

Returns
stringthe current stage: menu_main, menu_hunt, menu_options, menu_more, menu_help, menu_about, menu_shop, loading, hunt, menu_privacy, privacy_terms, privacy_policy (or none)

# game.inHunt() → boolean

Whether a hunt is running.

Returns
booleantrue while hunting (the hunter exists)
if game.inHunt() then world.spawnNear("trex") end

# game.area() → integer

The hunt's map.

Returns
integerthe area chosen in the hunt menu, 0 to 6

# game.version() → string

The game version.

Returns
string"2.0.1-pc"

# game.apiVersion() → integer

The version of this API. It grows by one with every release that adds to it; nothing is removed. A mod that needs newer functions says so in mod.json ("api": 2); older games then show why it does not run.

Returns
integerthe modding API's version (1 in this release)
if game.apiVersion() >= 2 then useNewThing() end

# game.timeScale(factor?) → number

Slow motion or fast forward for the whole game (creatures, the hunter, animations, timers of the game).

ParameterType
factor optionalnumber0.05 to 4; 1 = normal
Returns
numberthe factor
keys.bind("V", function() game.timeScale(game.timeScale() == 1 and 0.25 or 1) end)

# game.text(key, language?) → string|nil

One of the game's texts in the current (or a given) language.

ParameterType
keystringa key of the game's strings.csv, e.g. "STR_T_REX"
language optionalstring"en", "de", "fr", "es" ...
Returns
string|nilthe text, nil when there is no such key

# game.setText(key, text)

Replaces one of the game's texts (menus, messages, names). Texts the game shows from now on use it; menus already built show it the next time they are made. Letters outside Latin-1 become ? (the game's fonts lack them).

ParameterType
keystring
textstring|nilthe new text; nil = the original again
game.setText("STR_T_REX", "Rexy")

# game.language() → string

The game's language.

Returns
string"en", "de", "fr", "es" ...

# game.platform() → string

The operating system.

Returns
string"linux" or "windows"

# game.screen() → number, number

The window size in UI units (the coordinates of draw.* and ui.window).

Returns
numberwidth
numberheight

# game.paused() → boolean

Whether the hunt is paused.

Returns
booleantrue while the game menu (pause) is open

# game.dt() → number

The game's time step of the last frame (0 while paused).

Returns
numberseconds

# game.shots() → integer, integer

The hunt's shooting statistics.

Returns
integershots fired this hunt
integershots that hit

# game.message(text, seconds?, color?)

Shows a short message at the bottom right (the same as ui.toast).

ParameterType
textstringthe message
seconds optionalnumberhow long it shows (default 4)
color optionalColortext colour (default white)
game.message("A T-Rex is near!", 5, "orange")

# game.project(x, y, z) → number?, number?

hunt only

Where a world point appears on the screen, for labels and markers.

ParameterType
xnumberworld x
ynumberworld y (height)
znumberworld z
Returns
number?screen x (nothing when the point is behind the camera or not in a hunt)
number?screen y
local sx, sy = game.project(x, world.ground(x, z) + 300, z)
if sx then draw.text(sx, sy, "X marks the spot", "red", 20, "center") end