Lua/Global variables

From SRB2 Wiki
< Lua
Jump to: navigation, search

This is a list of all pre-defined global variables accessible for use in Lua.

Assorted

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)
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 game has been completed.
devparm boolean Returns true if the game is being run with the command line parameter -debug is set, false if not.
modifiedgame boolean Returns true if the game has been modified, false if not or the modification has custom gamedata.
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 level since it has loaded. This does not take into account the 4-second timer at the start of Race mode levels, so in this situation leveltime will be 4*TICRATE ahead of the displayed level time (set by a player's player.realtime value, which normally is synchronised with leveltime itself).
curWeather number The current weather type set locally.
globalweather number The current weather type set globally.
levelskynum number The current sky set locally.
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 lower 12 bits (0 to 0x0FFF) are the subtrack number, and the 15th bit (0x8000) determines whether reloading the current level will reset the music or not (on is yes, off is no).
server player_t The server's host player.
admin player_t The server's admin player. (this is nil if the admin player is also the host player)
emeralds number The variable containing all emeralds currently obtained during a Single Player or Co-op session.
gravity number The current global gravity value. (Default is FRACUNIT/2)
VERSIONSTRING string The game's version string.

Tables

This is a list of all table-based global variables. The majority of these serve as global arrays for most userdata types available in SRB2.

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 one of the MT_* constants.

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 is not usually needed

Whole entries for mobjinfo[] can be recreated from scratch if needed (see Lua/Basics > Freeslots, infotables, and other things SOC-related)

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 one of the S_* constants.

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/Basics > Freeslots, infotables, and other things SOC-related)

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 one of the sfx_* constants.

Whole entries for sfxinfo[] can be recreated from scratch if needed (see Lua/Basics > Freeslots, infotables, and other things SOC-related)

sprnames string

number
sprnames[SPR_NAME]

sprnames["NAME"]
#sprnames
→ Number of sprite set slots (522)
Converts a sprite prefix number to a string with just the 4-letter name, or vice versa. SPR_NAME is an integer that is expected to be one of the SPR_* constants; 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.
e.g. players[0] is the player_t userdata for player 1, players[1] is 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 name string for a skin, 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 one of the HUD_* constants.