Lua/Global variables

From SRB2 Wiki
< Lua
Jump to: navigation, search

This is a list of all pre-defined global variables and tables that are accessible by Lua.

Variables

This is a list of all non-table global variables. Note that all of these are read-only, i.e., their values cannot be edited by Lua.

Name Variable type Description
gamemap number The map number of the map currently being played.
maptol number The TypeOfLevel of the map currently being played. See Constants > TypeOfLevel flags.
ultimatemode boolean Returns true if playing in Ultimate mode, false if not.
mariomode boolean Returns true if the map is in Mario mode, false if not.
twodlevel boolean Returns true if the map is in 2D mode, false if not.
circuitmap boolean Returns true if the map is a Circuit map, false if not.
netgame boolean Returns true if currently in a netgame, false if not.
multiplayer boolean Returns true if currently playing a multiplayer game, false if not.
modeattacking boolean Returns true if playing in Record Attack mode, false if not.
splitscreen boolean Returns true if playing in two-player mode, false if not.
gamecomplete boolean Returns true if the game has been completed.
devparm boolean Returns true if the game is being run with the command line parameter -debug, false if not.
modifiedgame boolean Returns true if the game has been modified and the modification does not have a custom gamedata, false if not.
menuactive boolean Returns true if a menu is currently active, false if not.
paused boolean Returns true if the game is currently paused, false if not.
gametype number The current gametype being played. See Constants > Gametypes.
leveltime number The amount of time that has passed in the current level since it has been loaded, measured in tics. In most gametypes, this is normally equal to the time displayed on the HUD (when converted to tics). However, in Race and Competition modes, leveltime includes the 4-second pre-timer, meaning that leveltime will be 4*TICRATE tics ahead of the HUD's displayed time once the latter has started running. Note that leveltime will continue to increase after the level is finished, even after the HUD time has stopped, until the tally screen appears. The actual time displayed on the player's HUD is set by player.realtime (see player_t).
curWeather number The current weather type set locally. Note: This value is only calculated by the game locally for each player, and is not synchronized in netgames. Use at your own risk.
globalweather number The current weather type set globally.
levelskynum number The current sky set locally. Note: This value is only calculated by the game locally for each player, and is not synchronized in netgames. Use at your own risk.
globallevelskynum number The current sky set globally.
mapmusname string The name for the current music set for the map.
mapmusflags number The flags set for the current music being played. The lowest 12 bits (bits 0–11) are the subtrack number; this can be retrieved by checking mapmusflags & 0x0FFF. If the 15th bit (mapmusflags & 0x8000) is set, the music will be reset when the current level is reloaded.
server player_t The server's host player.
admin player_t The server's first admin player. This is nil if the admin player is also the host player. Note: This is deprecated since v2.1.21; use IsPlayerAdmin() instead.
emeralds number This variable stores which Chaos Emeralds have been obtained in the current Single Player or Co-op session, as a set of EMERALDn flags. See Chaos Emerald > Technical information.
gravity number The current global gravity value. The default value is FRACUNIT/2.
VERSIONSTRING string The game's version string. For SRB2 v2.1.23, this will return "v2.1.23".
token number The number of Special Stage Tokens collected in the current level.

Tables

This is a list of all global variables that are tables. Most of these serve as global arrays that give access to the userdata available for Lua.

Name Array type Usage # (Length) Description
mobjinfo mobjinfo_t mobjinfo[MT_NAME] #mobjinfo
→ Number of Object type slots (673)
This table is used to look up or modify attributes for a specific Object type, where MT_NAME is an integer that is expected to be the MT_* constant for the Object type in question.

Example usage:

mobjinfo[MT_SUPERRINGBOX].reactiontime = 20
local playerh = mobjinfo[MT_PLAYER].height
-- Example usage with mobj_t variables, using "mobj" as an example:
mobj.state = mobjinfo[mobj.type].spawnstate
-- mobj.info is a shortcut for mobjinfo[mobj.type],
--  i.e., mobj.info.VARIABLE == mobjinfo[mobj.type].VARIABLE
--  so this last example could be written more concisely as "mobj.state = mobj.info.spawnstate"

Whole entries for mobjinfo[] can be recreated from scratch if needed (see Lua/Freeslots and Object resources).

states state_t states[S_NAME] #states
→ Number of state slots (4519)
This table is used to look up or modify attributes for a specific state, where S_NAME is an integer that is expected to be the S_* constant for the state in question.

Example usage:

states[S_SPOSS_STND].sprite = SPR_RBUZ
local standtics = states[S_PLAY_STND].tics
-- Example usage with mobj_t variables, using "mobj" as an example:
local st = states[mobj.state]
st.action(mobj, st.var1, st.var2)
-- calls the action for mobj's current state

Whole entries for states[] can be recreated from scratch if needed (see Lua/Freeslots and Object resources).

sfxinfo
(alt.: S_sfx)
sfxinfo_t sfxinfo[sfx_name] #sfxinfo
→ Number of sound slots (1209)
This table is used to look up or modify attributes for a specific sound, where sfx_name is an integer that is expected to be the sfx_* constant for the sound in question.

Whole entries for sfxinfo[] can be recreated from scratch if needed (see Lua/Freeslots and Object resources).

sprnames string

number
sprnames[SPR_NAME]

sprnames["NAME"]
#sprnames
→ Number of sprite set slots (522)
Converts a sprite prefix number to a string consisting of the 4-letter sprite name, or vice versa. SPR_NAME is an integer that is expected to be the SPR_* constant for the sprite prefix number in question. Likewise, "NAME" can only be a four-letter prefix belonging to an existing sprite set.

Example usage:

print(sprnames[SPR_NULL]) -- prints "NULL"
print(sprnames["NULL"]) -- prints 0 (the value of SPR_NULL)
-- Example usage with mobj_t variables, using "mobj" as an example:
print("sprite = SPR_"..sprnames[mobj.sprite])
-- prints out prefix of mobj's sprite
players player_t players[playernum] #players
→ Number of player slots (32)
This table is used to look up the properties of a player, where playernum is an integer between 0 and 31.
For example, players[0] is the player_t userdata for player 1, players[1] for player 2, and so on.
skins skin_t skins[skinnum]
or skins["skinname"]
#skins
→ Number of skin slots (32)
This table is used to look up the properties of a skin, where skinnum is an integer between 0 and 31. Alternatively, skinname is the skin's name attribute, which can be given instead of the skin number.

Example usage:

print(skins[0].name) -- prints "sonic"
print(skins["sonic"].name) -- also prints "sonic"
S_StartSound(nil, skins[0].soundsid[SKSTHOK]) -- plays sfx_thok
-- Example usage with mobj_t variables, using "mobj" as an example:
print("my character's name is "..skins[mobj.skin].realname)
-- prints out the "real" name for the mobj's skin
mobj.color = skins[mobj.skin].prefcolor
-- changes mobj's color to skin's prefcolor
mapthings mapthing_t mapthings[i] #mapthings
→ Number of Things in map
This table is used to look up the properties of a Thing.
vertexes vertex_t vertexes[i] #vertexes
→ Number of vertices in map
This table is used to look up the properties of a vertex.
lines line_t lines[i] #lines
→ Number of linedefs in map
This table is used to look up the properties of a linedef.
sides side_t sides[i] #sides
→ Number of sidedefs in map
This table is used to look up the properties of a sidedef.
subsectors subsector_t subsectors[i] #subsectors
→ Number of subsectors in map
This table is used to look up the properties of a subsector.
sectors sector_t sectors[i] #sectors
→ Number of sectors in map
This table is used to look up the properties of a sector.
mapheaderinfo mapheader_t mapheaderinfo[i] #mapheaderinfo
→ Number of map slots (1035)
This table is used to look up the properties of a level header.
hudinfo hudinfo_t hudinfo[HUD_NAME] #hudinfo
→ Number of HUD items (30)
This table is used to look up or modify attributes for a specific HUD item, where HUD_NAME is an integer that is expected to be the HUD_* constant for the HUD item in question.
  Lua [view]
Language features SyntaxMetatables
SRB2 data ActionsConstantsFunctionsGlobal variablesHooksUserdata structures
Tutorials Freeslots and Object resourcesCustom player ability