Lua/Kart/Userdata structures

From SRB2 Wiki
< Lua
Jump to navigation Jump to search

This article lists all the userdata types available for Lua in SRB2 Kart, as well as the variables they contain.

Notes

Refer to this section to help understand the contents of the following tables.

Column headers

  • Name: The name of the variable.
  • Type: The variable's type. See Variable types for a list of possible types.
  • Accessibility: Indicates whether it is possible to read (retrieve) or write (modify) the variable's value. Note that in some cases where the variable is a table or another userdata object, it may be not be possible to change the variable's value (i.e., exchange the table/userdata object for a different one), but it may still be possible to access and modify the variables of the table/userdata object. In these cases, the column makes a distinction between Table/Userdata, which is marked as Read-only, and Table/Userdata variables, which are marked as Read+Write.
  • Description/Notes: Gives additional information about the variable and how it can be used.

Variable types

This section lists the variable types that can appear under the Type column for tables in this article:

Non-numerical

  • string: Plain text (e.g., "sonic" or "eggman").
  • boolean: Can only have the value true or false.
  • function: The variable is a function.
  • userdata (mobj_t, player_t, etc.): One of the userdata types listed in this article.

Basic numerical

Signed:

  • SINT8: Signed 8-bit integer. Values range from -128 to 127.
  • INT16: Signed 16-bit integer. Values range from -32768 to 32767.
  • INT32: Signed 32-bit integer. Values range from -2147483647 to 2147483648.

Unsigned:

  • UINT8: Unsigned 8-bit integer. Values range from 0 to 255.
  • UINT16: Unsigned 16-bit integer. Values range from 0 to 65535.
  • UINT32: Unsigned 32-bit integer. For technical reasons, this is treated as identical to INT32 in Lua.

Derived numerical

These types are identical to one of the basic numerical types listed above, but they use a different name to indicate that the variable's value has a special significance.

  • fixed_t: Same as INT32. This indicates that the variable is a fixed-point number, where multiples of FRACUNIT represent integer numbers and values in-between represent non-integer real numbers (e.g., 3*FRACUNIT/2 represents 1.5). The minimum and maximum values for this type can be expressed as -32768*FRACUNIT and (32768*FRACUNIT)-1. See also Lua/Functions > Fixed-point math.
  • angle_t: Same as UINT32. This indicates that the variable represents an angle, and so should be used with the ANG*/ANGLE_* constants unless otherwise stated. Note that ANGLE_180 and larger (including ANGLE_MAX) will be shown as negative numbers in Lua due to being confined to INT32 limits. See also Lua/Functions > Angle math.
  • tic_t: Same as UINT32. This indicates that the variable represents a time in tics. To convert a time in seconds to tics, multiply the number of seconds by TICRATE (35 tics = TICRATE = 1 second).

Other

  • enum (prefix): The variable is an enumerated type. While it can have any integer value, it is intended to have the value of one of the constants with the prefix prefix. For example, if a variable's type is denoted as "enum (MT_*)", its value is expected to be equal to one of the MT_* constants. The type description will link to an article listing the available constants with the given prefix.
  • type array: This a table containing multiple entries of type type. The type of variables accepted as keys may be given in the Description/Notes column.

General

These userdata types represent components of the game related to Objects or players.

mobj_t

This userdata type represents an Object. In the examples below, mobj is used as the name of the mobj_t variable. An access to a variable var of mobj_t is written as mobj.var.

General
Accessibility Read+Write
Allows custom variables Yes
mobj_t structure
Name Type Accessibility Description/Notes
valid boolean Read-only Returns true if the Object is valid (i.e., still exists), false if not.
x fixed_t Read-only The Object's absolute X position in the map. To modify this value, use a function such as P_TeleportMove rather than editing it directly.
y fixed_t Read-only The Object's absolute Y position in the map. To modify this value, use a function such as P_TeleportMove rather than editing it directly.
z fixed_t Read+Write The Object's absolute Z position in the map.
snext mobj_t Userdata: Read-only
Userdata variables: Read+Write
The next Object in the linked list that contains all Objects in the sector.
sprev N/A None Unusable by Lua – this is just the previous Object's snext pointer, which points to this Object.
angle angle_t Read+Write The absolute angle the Object is facing horizontally. 0 is East, ANGLE_90 is North, ANGLE_180 is West, and ANGLE_270 is South.
sprite enum (SPR_*) Read+Write The sprite prefix of the sprite the Object is currently displaying. Note that each time an Object switches states, this value is automatically reset to the new state's sprite prefix.
frame UINT32 Read+Write The sprite frame the Object is currently displaying, plus additional frame flags that set further properties of the current state, including full brightness, animation, and translucency (see State > Attributes). Note that each time an Object switches states, this value is automatically reset to the new state's sprite frame.
anim_duration UINT16 Read+Write If mobj.frame currently has the frame flag FF_ANIMATE set, this is the duration in tics between each frame in the state's animation. Otherwise, this has no effect on the Object's animation. By default, this is set to the current state's Var2 value.
touching_sectorlist N/A None Unusable by Lua – not yet implemented.
subsector subsector_t Read-only The subsector the Object is currently in. To obtain the sector the Object is in, use mobj.subsector.sector. Note that mobj.subsector will be nil for Objects currently being removed.
floorz fixed_t Read-only The absolute "floor" position for the Object, i.e., the height that it considers to be the floor. This can be different from the floor height of the sector the Object is in, for example if it is above a solid FOF. Note that this value is not flipped to a ceiling position if the Object is in reverse gravity.
ceilingz fixed_t Read-only The absolute "ceiling" position for the Object, i.e., the height that it considers to be the ceiling. This can be different from the ceiling height of the sector the Object is in, for example if it is below a solid FOF. Note that this value is not flipped to a floor position if the Object is in reverse gravity.
radius fixed_t Read+Write The current radius of the Object. When the Object's scale is modified, this is reset to the default radius for the Object's Object type, multiplied with the new scale. Otherwise this is freely adjustable; the minimum value is 0.
height fixed_t Read+Write The current height of the Object. When the Object's scale is modified, this is reset to the default height for the Object's Object type, multiplied with the new scale. Otherwise this is freely adjustable; the minimum value is 0. For players, however, note that this value is continuously corrected/modified to be either the default player height or a specific height used in special situations, such as when spinning.
momx fixed_t Read+Write The Object's current X-axis momentum. Positive values will cause the Object to move to the East, negative values to the West. If you want the Object to move horizontally at an angle that is not entirely along the X-axis, the X-axis momentum should be the desired momentum multiplied by the cosine of the angle – if mom is the desired momentum and h-angle is an angle_t variable representing the angle between the X-axis and Y-axis, then you should set mobj.momx = mom*cos(h-angle). If the movement has a vertical component as well, you need to multiply the cosine of the vertical angle between the Z-axis and the horizontal plane as well – if v-angle is the vertical angle (with a value of 0 being completely horizontal), then you should set mobj.momx = mom*cos(h-angle)*cos(v-angle).
momy fixed_t Read+Write The Object's current Y-axis momentum. Positive values will cause the Object to move to the North, negative values to the South. If you want the Object to move horizontally at an angle that is not entirely along the Y-axis, the Y-axis momentum should be the desired momentum multiplied by the sine of the angle – if mom is the desired momentum and h-angle is an angle_t variable representing the angle between the X-axis and Y-axis, then you should set mobj.momy = mom*sin(h-angle). If the movement has a vertical component as well, you need to multiply the cosine of the vertical angle between the Z-axis and the horizontal plane as well – if v-angle is the vertical angle (with a value of 0 being completely horizontal), then you should set mobj.momy = mom*sin(h-angle)*cos(v-angle).
momz fixed_t Read+Write The Object's current Z-axis momentum. Positive values cause the Object to move upwards, negative values downwards. If you want the movement to have a horizontal component as well, you need to multiply the sine of the vertical angle between the Z-axis and the horizontal plane as well – if mom is the desired momentum and v-angle is an angle_t variable representing the vertical angle (with a value of 0 being completely horizontal), then you should set mobj.momz = mom*sin(v-angle).
pmomz fixed_t Read+Write If the Object is standing on a moving floor, this is the Z-axis momentum of the floor.
tics INT32 Read+Write The current value of the Object's state timer, which decreases by 1 each tic until it reaches 0. At this point, the Object will switch to a new state and this value will be reset to the new state's tic duration. If the value is -1, the current state will have infinite duration.
state enum (S_*) Read+Write The number of the state the Object is currently in. When the value of this is changed, Lua will automatically switch the current state to the new value. mobj.sprite, mobj.frame, mobj.tics will be changed to the new state's sprite, frame and tics values respectively. Additional adjustments may be made for player Objects specifically however (such as player animation speeds and switching to superform states). Switching to the state S_NULL will make the Object disappear, unless it is a player Object (this will cause the game to print an error in the console instead).

Note that changing the value of mobj.state directly in Lua will cause the new state's action to be called automatically. To avoid this, the function P_SetMobjStateNF should be used instead.

flags UINT32 Read+Write The Object's current primary Object flags (use MF_* constants). When the Object is first spawned, this is automatically set to the flags attribute of the Object's Object type. Afterwards it can be adjusted freely.
flags2 UINT32 Read+Write The Object's current secondary Object flags (use MF2_* constants).
eflags UINT16 Read+Write The Object's current extra Object flags (use MFE_* constants).
skin string Read+Write The current skin applied to the Object. For Objects with mobj.sprite set to SPR_PLAY, this will change the appearance of the Object's sprites to that of the character the skin is associated with. This is most commonly used by players, but Extra Life Monitors, Level End Signs, ghost trails, and player thok trails also apply a skin in some situations.
color UINT8 Read+Write The current skin color applied to the Object (use SKINCOLOR_* constants). When modifying this for regular Objects, this will by default re-map the green range of colors (palette color #s 160–175) to the specified range for the color name given. However, for Objects using SPR_PLAY this can use the current skin's startcolor parameter instead to set the range of colors to color remap.
bnext mobj_t Userdata: Read-only
Userdata variables: Read+Write
The next Object in the linked list that contains all Objects in the blockmap's current block.
bprev N/A None Unusable by Lua – this is just the previous Object's bnext pointer, which points to this Object.
hnext mobj_t Read+Write The next Object in the "hoop". Originally intended for use with NiGHTS hoops, but is usable for other purposes as well.
hprev mobj_t Read+Write The previous Object in the "hoop". Originally intended for use with NiGHTS hoops, but is usable for other purposes as well.
type enum (MT_*) Read+Write The Object's current Object type. If the value is changed via Lua (which is usually not necessary), mobj.info will automatically be modified at the same time to point to the mobjinfo_t entry for the new Object type.

Important note: For Objects spawned on the map via a Thing, modifying mobj.type to an Object type without a corresponding Thing type (i.e., mobj.info.doomednum has a value of -1) will cause the Object and its Thing to not be linked properly for players joining a netgame. This is because, when creating the $$$.sav file, the networking code incorrectly assumes Objects of these types will never have a corresponding Thing, regardless of the value of mobj.spawnpoint for any particular Object. This results in mobj.spawnpoint for such an Object becoming nil for any players joining the netgame.

info mobjinfo_t Userdata: Read-only
Userdata variables: Read+Write
This points to the mobjinfo_t entry for the Object's Object type, which lists the Object type's properties. As such, it is a shortcut for mobjinfo[mobj.type]. mobj.info itself cannot be changed directly, but if mobj.type is changed, mobj.info will automatically be changed to point to the mobjinfo_t for the new Object type.
health INT32 Read+Write The Object's current amount of health points. When the Object is first spawned, this is automatically set to the spawnhealth attribute of the Object's Object type. Afterwards it can be adjusted freely. For Objects that do not need a health value, this can be used for miscellaneous purposes if desired.
movedir angle_t Read+Write Used to indicate movement direction for A_Chase and related, using the DI_* constants. Otherwise, this can be used for any miscellaneous purpose whatsoever.
movecount INT32 Read+Write Used as a timer before the Object changes direction (usually if mobj.movecount == 0) for A_Chase and related. Otherwise, this can be used for any miscellaneous purpose whatsoever.

In SRB2Kart, also used by MT_FLOATINGITEM to determine how many items it will give the Player that picks it up.

target mobj_t Read+Write Generally used as a "target" Object for enemies and similar to chase towards/fire at. Projectiles (Objects with MF_MISSILE) should set this to the Object that fired them, so they cannot harm/crash into the firer. Otherwise, this can be used to link any related Object at all if needed.
reactiontime INT32 Read+Write Used as a timer to delay certain behavior such as attacks (usually if mobj.reactiontime == 0) for a number of actions, including A_Chase and related. When the Object is first spawned, this is automatically set to the reactiontime attribute for the Object type the Object belongs to, but can freely be adjusted afterwards. For players, this is used by some types of teleports to prevent the them from moving until it has reached 0. Otherwise, this can be used for any miscellaneous purpose whatsoever.
threshold INT32 Read+Write Used as a timer before switching targets (usually if mobj.threshold == 0) for A_Chase and related. Otherwise, this can be used for any miscellaneous purpose whatsoever.

In Kart, this is also used by most of the thrown item as a timer to make sure they don't hit the Player that threw them for the first few frames of its existence.

It also is used by MT_FLOATINGITEM to determine what object type is to be awarded to the Player that picks it up.

player player_t Userdata: Read-only
Userdata variables: Read+Write
For player Objects, this points to the player's properties (e.g., mobj.player.pflags or mobj.player.powers[pw_invulnerability]). It is recommended mobj.player.mo is not used as this just points back to mobj itself, which is redundant. For regular Objects mobj.player will return nil.
lastlook INT32 Read+Write Used to store the player number of the last player targeted for A_Chase and related. Otherwise, this can be used for any miscellaneous purpose whatsoever.
spawnpoint mapthing_t Read+Write For Objects that have been spawned on the map via a Thing (or "spawn point"), this points to the Thing that spawned it by default. If one doesn't exist, this returns nil. However, this variable can be adjusted to point to a different Thing if needed, or to not point to any Thing at all by using mobj.spawnpoint = nil.

Important notes:

  • If an Object belongs to an Object type that does not have a corresponding Thing type number (i.e., mobj.info.doomednum has a value of -1), modifying mobj.spawnpoint to a non-nil value will cause the Object and its Thing to not be linked properly for players joining a netgame. This is because, when creating the $$$.sav file, the networking code incorrectly assumes the Object will never have a corresponding Thing, regardless of the value of mobj.spawnpoint. This results in mobj.spawnpoint for such an Object becoming nil for any players joining the netgame.
  • It is recommended not to make multiple Objects point to the same Thing; for players joining a netgame, $$$.sav will edit mobj.spawnpoint.mobj for all Objects with a mobj.spawnpoint value (except for Object types with no corresponding Thing type; see note above) to point back to mobj, assuming it is the Object that the Thing (mobj.spawnpoint) originally spawned. As mobj.spawnpoint.mobj can only point to one Object at a time, this may result in it pointing to a different Object for players who have just joined the game.
  • For special placement patterns and player starts, mobj.spawnpoint is nil for all Objects spawned by these Thing types. For standard and customizable Hoops, only the hoop center Object will have a non-nil mobj.spawnpoint value.
tracer mobj_t Read+Write Generally used as a secondary "target" Object when mobj.target is already in use. For players, this is often used to link players to the next waypoint to move towards, or the Object the player is being carried by currently.
friction fixed_t Read+Write The Object's current "friction" value. Contrary to real-life friction physics, this is used as a multiplier for mobj.momx and mobj.momy to slow down or speed up the Object when touching the ground. The higher the value of mobj.friction is, the less sludgy/more slippery the floor surface becomes to the Object.
In general:
  • mobj.friction values smaller than FRACUNIT will slow down the Object on the ground.
  • mobj.friction values greater than FRACUNIT will speed up the Object on the ground.
  • mobj.friction values equal to FRACUNIT will not slow down nor speed up the Object at all.

The default mobj.friction value for most Objects is 62914.

movefactor fixed_t Read+Write This variable may have formerly been used for friction-related purposes, but currently it has no general purpose and is used by various Object types for miscellaneous purposes. For example, spawning an Orbinaut from another Orbinaut through the MobjDeath hook would require you to set the secondary Orbinaut's movefactor in order for it to move; otherwise, it would simply roll in place upon spawning.
fuse INT32 Read+Write Commonly used as a timer before the Object disappears or does something else, which automatically decreases by 1 each tic until it reaches 0. This is also used for miscellaneous purposes, but this has to be kept the same value always for this to work.
watertop fixed_t Read+Write The absolute "water top" position for the Object. If the Object is currently touching a water FOF, this is the top height of the water FOF. Otherwise, it defaults to mobj.z - 1000*FRACUNIT.
waterbottom fixed_t Read+Write The absolute "water bottom" position for the Object. If the Object is currently touching a water FOF, this is the bottom height of the water FOF. Otherwise, it defaults to mobj.z - 1000*FRACUNIT.
mobjnum N/A None Unusable by Lua – this is used by the networking code to number the Objects in the game inside $$$.sav and so shouldn't be available for Lua usage.
scale fixed_t Read+Write The Object's current scale. The default scale is FRACUNIT. When this is modified by Lua with mobj.scale = newvalue, this will automatically use P_SetScale(mobj, newvalue) internally to adjust the Object's radius and height, but will also change mobj.destscale to match. This means using P_SetScale itself directly is not redundant as it does not affect mobj.destscale internally, allowing gradual scale changes (rather than instantaneous) to be possible. For consistent results, it's best to modify mobj.scale using a value relative to mapobjectscale, as Kart maps may have a scale higher or lower than FRACUNIT.
destscale fixed_t Read+Write The Object's destination scale. If the Object does not currently have this scale, it will gradually change the value of mobj.scale to match this value.
scalespeed fixed_t Read+Write The Object's scale-changing speed, for when the Object is gradually changing scale to reach the value of mobj.destscale. The value used in most cases is FRACUNIT/12, but this can be adjusted to speed up or slow down the scale-changing if needed.
extravalue1 INT32 Read+Write An extra variable that can be used for miscellaneous purposes. Note that some of SRB2's default Objects already use this variable. This variable is used to distinguish Self-Propelled Bomb explosions from Eggman Monitor explosions, as they both use the same object when triggering their respective detonations (MT_SPBEXPLOSION).
extravalue2 INT32 Read+Write An extra variable that can be used for miscellaneous purposes. Note that some of SRB2's default Objects already use this variable. In particular, A_Repeat uses it to set the repeat count.
cusval INT32 Read+Write The Object's "custom value", ported from the v2.0 modification SRB2Morphed. It is unused by SRB2's default Objects and was originally intended as an extra variable for SOC scripting, although it can be used freely for any purpose. Several actions, such as A_CheckCustomValue or A_CusValAction, are available that make use of this value and mobj.cvmem.
cvmem INT32 Read+Write This is intended as a "memory" for the Object's "custom value", allowing you to store a copy of the custom value and then recall it later, after the actual custom value may have changed. The actions A_CheckCusValMemo and A_UseCusValMemo are available for using the custom value memory.
standingslope pslope_t Read-only The slope that the Object is standing on, or nil if the Object is not standing on a slope.
colorized boolean Read+Write When set to true, the whole Object will be colorized with its mobj.color in the same way an invincible player would. Can even be used on Objects that normally cannot change colours granted that its color field has been set.

player_t

This userdata type represents the properties of a player that are independent of the player Object and may carry over between maps. In the examples below, player is used as the name of the player_t variable. An access to a variable var of player_t is written as player.var.

NOTE: A lot of player_t variable are left unused in SRB2Kart, these variables are not listed here, but are still accessible for miscellaneous purposes if needed.

General
Accessibility Read+Write
Allows custom variables Yes
# (Length) #player → player number
#player.powers → total number of powers (23)
player_t structure
Name Type Accessibility Description/Notes
valid boolean Read-only Returns true if the player is valid (i.e., still exists), false if not.
name string Read-only The player's name.
mo mobj_t Read+Write Points to the mobj_t data representing the player Object.

Note: By default, player.mo is a pre-determined Object of the type MT_PLAYER. It is possible to change player.mo to a different Object of any type, but not to nil. However, it is not recommended to use a different Object type than MT_PLAYER – the sprites for the player's character will still appear when walking, running, etc. regardless of the Object's type, and the player may also not behave properly when using particular special map effects if they are not using an MT_PLAYER Object.

If the player is currently a spectator, player.mo will return nil.

cmd ticcmd_t Userdata: Read-only
Userdata variables: Read+Write
Points to the player's button information, i.e., what buttons are currently being pressed. Properties of this can be modified freely, but player.cmd itself cannot be assigned a new value.
playerstate enum (PST_*) Read+Write The player's current player state (either living, dead or respawned).
viewz fixed_t Read+Write The player's absolute viewing height (or viewing Z position) used by the first-person camera. The game will automatically update this variable every tic; the exact calculation used depends on the player's gravity direction:
  • Normal gravity: player.mo.z + player.viewheight + (bobbing displacement)
  • Reverse gravity: player.mo.z + player.mo.height - player.viewheight + (bobbing displacement)

In both cases, (bobbing displacement) is a displacement value calculated using player.bob, which causes the player's view to appear to "bob" up and down as they walk. It is only added if the player is on the ground and using the first-person camera.

Note: If not modified by Lua, this value is only calculated by the game for local players, and thus isn't network safe. Use at your own risk.

viewheight fixed_t Read+Write The player's relative viewing height used by the first-person camera. This is normally set to the value of the console variable viewheight (scaled to the player's current scale), though sometimes it may be reduced for effects such as landing on the ground – in these cases, player.deltaviewheight is used to gradually return player.viewheight to its normal value.

Note: If not modified by Lua, this value is only calculated by the game for local players, and thus isn't network safe. Use at your own risk.

deltaviewheight fixed_t Read+Write The value to re-adjust player.viewheight by the next tic when it has moved away from the normal height (e.g., when landing on the ground, the viewheight dips a bit then rises back up – both the lowering and rising is done by player.deltaviewheight).

Note: If not modified by Lua, this value is only calculated by the game for local players, and thus isn't network safe. Use at your own risk.

aiming angle_t Read+Write The player's current vertical viewing angle; player.aiming = 0 would be facing directly forward, player.aiming > 0 would face upwards, and player.aiming < 0 would face downwards. If player.pflags has the flag PF_FLIPCAM, the value of player.aiming will be flipped whenever the player is given reverse gravity or reverts back to normal gravity.

Do note that in SRB2Kart, this value is only used for spectator Players which Lua cannot access.

Note: This value is limited to a maximum of ANGLE_90 -1 in either direction; however, the Software renderer limits what is seen in-game to ANGLE_90 - ANG10.

health INT32 Read+Write A copy of player.mo's health value. In kart, it's either 0 if the player is dying (fell in a pit / used the respawn command), or a non-null value if the player is alive.
powers[powername] UINT16 array Table: Read-only
Table entries: Read+Write
A table containing the current values for all powers for the player, where powername is an integer expected to be one of the pw_* constants. The table itself cannot be directly reassigned, but entries in it can be accessed or modified. Use of the values depends on the power selected – see the Powers article for more information on each power.

Example usages of this variable:

player.powers[pw_flashing] = TICRATE

This gives player a second of invulnerability flashing frames.

pflags enum (PF_*) Read+Write Contains the internal player flags currently applied to the player, e.g., PF_TIMEOVER for when the player has ran out of time in Race.

Do note that most of these constants are unused in SRB2Kart.

panim enum (PA_*) Read+Write The player's current animation – in the source code, this variable is frequently used as a shortcut in place of explicitly checking a range of states for each player animation (e.g., PA_WALK covers states S_PLAY_RUN1 to S_PLAY_RUN8). This can also be modified to allow for custom states to act as if they were the animation for certain extra effects to work with them. Do note that player.panim is corrected every time the player's state is changed.
flashcount UINT16 Read+Write Amount of time the player is set to the palette set by player.flashpal. P_FlashPal can be used to set this along with player.flashpal.
flashpal UINT16 Read+Write Sets the palette number displayed on the screen for the player. player.flashcount also has to be set for this to have any affect when modified. P_FlashPal can be used to set this along with player.flashcount.
skincolor UINT8 Read+Write The player's "normal" skin color (SKINCOLOR_* constants are to be used). In Single Player, this is basically a copy of the prefcolor set for the player's character; in multiplayer, it is the player's chosen skin color selected in the Player Setup menu or through the console variable COLOR. Values above SKINCOLOR_GOLD should not be used for this variable.

It is important to note that player.skincolor is not the actual skin color displayed in-game (which would be player.mo.color), but a backup skin color variable for player.mo.color to reference – this is useful for when the player has turned Super or collected a power-up that changes their skin color (e.g., the Fire Flower, or Mario mode's invincibility), where player.skincolor can then be used to restore the player's "normal" skin color when they are no longer Super or have lost the power-up.

For instance, when the player is using Invincibility, player.mo.color is cycled through different colours, while player.skincolor remains the original skin color the player had before. Afterwards, if the player lost this power-up, player.mo.color is re-set to the value of player.skincolor, restoring the player's original skin color.

score UINT32 Read+Write In Kart, this is used to determine where a Player is to spawn in Race, if their score is higher than another Player's, they will spawn to the next Player Spawn Point.

In other words, the more score a Player has related to the other Players, the more they will spawn towards Player Spawn Point #16. If you want to check for a Player's points in the rankings, use marescore instead.

lives SINT8 Read+Write Is set to 0 when the player has run out of time in Race. (No Contest).
speed fixed_t Read+Write The absolute "real" speed the player is currently moving at in any direction. This is calculated using player.rmomx and player.rmomy normally &ndash.

In SRB2Kart, this value is also used to determine your turning arc as well as Spring Pad behavior (such as the height you will be launched at). Modifying this value does NOT modify the Player's actual movement speed.

deadtimer INT32 Read+Write The player's death timer, the amount of time the player has been dead for. Used to automatically trigger effects after some time such as respawning.
exiting tic_t Read+Write The player's "exiting" timer, when all Player's exiting are 1 (or have No Contested), the level will end. By default player.exiting is set to 0, to mark that the player is not currently "exiting" the level. When it is set to a non-zero value, the following effects occur:
  • The player becomes invincible but unable to move.
  • The camera stays still
cmomx fixed_t Read+Write The player's "conveyor" momx, i.e., the x-momentum from conveyor belts, wind, or currents.
cmomy fixed_t Read+Write The player's "conveyor" momy, i.e., the y-momentum from conveyor belts, wind, or currents.
rmomx fixed_t Read+Write The player's "real" momx, i.e., the x-momentum from the player themselves (player.mo.momx - player.cmomx). Modifying this will not change the player's actual x-momentum (modify player.mo.momx to do this).
rmomy fixed_t Read+Write The player's "real" momy, i.e., the y-momentum from the player themselves (player.mo.momy - player.cmomy). Modifying this will not change the player's actual y-momentum (modify player.mo.momy to do this).
realtime tic_t Read+Write The timer value displayed on the HUD. Do note that it's different from leveltime as the timer is still 0 during the starting sequence in which leveltime still increments.

The value of this timer can thus be summed up to player.realtime = leveltime - (6*TICRATE + (3*TICRATE/4))

Note that when the player has finished the level, player.realtime will stop increasing, marking the time the player finished the level at. This final value is then used by the game for awards or bonuses, depending on the game mode or gametype:

  • If in Race, it is compared with that of other players' to calculate the winners of the round.
  • If in Time Attack, it is saved as the time the replay finished at.
laps UINT8 Read+Write Used in Race to count the number of laps or sections the player has gone through.
starpostx INT16 Read+Write The saved x-position for the last checkpoint the player has touched, to be used when the player respawns at the checkpoint after dying.
starposty INT16 Read+Write The saved y-position for the last checkpoint the player has touched, to be used when the player respawns at the checkpoint after dying.
starpostz INT16 Read+Write The saved z-position for the last checkpoint the player has touched, to be used when the player respawns at the checkpoint after dying.
starpostnum INT32 Read+Write The saved starpost number for the last checkpoint the player has touched. Used to prevent the player from skipping starposts in Circuit mode maps, as they need to touch every single starpost number in order before completing a lap.
starposttime tic_t Read+Write The saved level time for the last checkpoint the player has touched, to be used for resetting the level time to a particular time when the player respawns at a starpost after dying.
starpostangle angle_t Read+Write The saved angle for the last checkpoint the player has touched, to be used when the player respawns at the checkpoint after dying.
marescore UINT32 Read+Write The Player's points in the Scoreboard.
onconveyor INT32 Read+Write When the player is in a sector affected by a pushing or scrolling effect, player.onconveyor will be set to 2 or 4 respectively. player.onconveyor is then used to determine when and whether to set player.cmomx and player.cmomy to 0 or not.
awayviewmobj mobj_t Read+Write Pointer to the player's current alternate view camera Object, this will be the viewpoint of the player for as long as player.awayviewtics has not reached 0.
awayviewtics INT32 Read+Write The player's alternate view camera timer. This will decrease until it reaches 0. Otherwise when player.awayviewtics is set, player.awayviewmobj is the viewpoint of the player. if player.awayviewmobj is not already set when player.awayviewtics is set, this will auto-set player.awayviewmobj to the player itself (player.mo).
awayviewaiming angle_t Read+Write The player's alternate view camera vertical aiming angle. Similar to player.aiming except this applies to the alternative view point rather than the actual player's camera for when the camera switches back.
spectator boolean Read+Write Returns true if the player is a spectator, otherwise this will return false.
jointime tic_t Read+Write The amount of time the player has been in-game, and even counts up when the game is paused.
kartspeed UINT8 Read+Write The Player's kart speed stat. Usually locked between 1 and 9, but can be set to absurd values with Lua.
kartweight UINT8 Read+Write The Player's kart weight stat. Usually locked between 1 and 9, but can be set to absurd values with Lua.
frameangle angle_t Read+Write The Player's visual angle that the sprite is facing. Used for spinout among other things.
splitscreenindex UINT8 Read-only Helps determine if a player is a splitscreen player (from 0-3).
kartstuff[kartstufftype] INT32 array Table: Read-only
Table entries: Read+Write
A table containing most of the Kart-specific variables, works similarly to player.powers. See the list of kartstufftype_t constants below.

kartstufftype_t

Constants to be used in a Player's kartstuff array. While these are constants and not actually Userdata, they basically replace new Userdata entries in SRB2Kart and might as well be considered as such and listed here. Reminder that all of these constants link to INT32 entries in the kartstuff array.

An example of usage is player.kartstuff[k_positiondelay] = 4

Name Description
k_position Position the player is in. Used for the rankings to the side of the screen as well as the bottom-right position number in Race.
k_oldposition Keeps track of the position you were in last frame, this is used when passing someone to play the taunt sound.
k_positiondelay Used to make the position number grow in size when passing / being passed.
k_prevcheck Distance to the previous waypoint. (Waypoints as in the Boss Waypoint items placed near Checkpoints in maps.)
k_nextcheck Distance to the next waypoint. (Waypoints as in the Boss Waypoint items placed near Checkpoints in maps.)
k_waypoint Stores the waypoint number the player is at.
k_starpostwp Duplicate of k_waypoint for various purposes.
k_starpostflip Only set when passing through a Starpost Activator Sector in reverse gravity. If set to a non-null value, the Player will respawn in reverse gravity.
k_respawn Timer for respawning. After respawning, decrements until it hits 0, at which you will be free to start initiating a Drop Dash until you hit the floor.

Also handles the Death Egg Zone laser effect seen when respawning.

k_dropdash Timer for intiating a Drop Dash. Increments if you hold Accelerate when falling after respawning.
k_throwdir Keeps track of what directional button is held for throwing: 1 = forward, 0 = none, -1 = backwards.

This is used to know where to throw some items.

k_lapanimation Timer to show the Lap HUD Animation
k_laphand GFX to use in the Lap HUD Animation:

0 = None (Used if alone, or in Time Attack, in which it is replaced by a Clock.)

1 = OK Hand (used when a Player is in 1st place)

2 = Thumbs up (Used if a Player is placing in the top half)

3 = Thumbs down (Used if a Player is placing in the lower half)

k_cardanimation Used for battle HUD screen-wide animations.
k_voices Prevents character voices from playing more than they should depending on the User's settings.
k_tauntvoices As its name doesn't tell, it's used to prevent item-related voices from Playing too much.
k_instashield Insta Shield invincibility animation timer
k_enginesnd Engine sound number the Player is currently using. (Depends on the Player's kartspeed and kartweight
k_floorboost Prevents the Sneaker sound from repeating itself when a Player hits a Boost Pad.
k_spinouttype Determines whether Spinout should thrust a Player forwards (1) or not (0)
k_drift Player is drifting, the farther away from 0 this value is, the sharper the turn is. When drifting Right, player.kartstuff[k_drift] < 0, when drifting Left, player.kartstuff[k_drift] > 0
k_driftend Used to adjust angle after a drift, since it changes the Player's angle.
k_driftcharge Player's driftspark charge.

If player.kartstuff[k_driftspark] >= K_GetKartDriftSparkValue(player)*4, then the Player has rainbow driftsparks.

If player.kartstuff[k_driftspark] >= K_GetKartDriftSparkValue(player)*2, then the Player has red driftsparks.

If player.kartstuff[k_driftspark] >= K_GetKartDriftSparkValue(player), then the Player has blue driftsparks.

If player.kartstuff[k_driftspark] < K_GetKartDriftSparkValue(player), then the Player has no driftspark.

k_driftboost Timer for the driftspark boost.
k_boostcharge Timer for how long the start boost has been charged up for.

If < 35, no startboost is awarded (If > 17 and < 35, then the skid sound is played as well)

If >= 35 and <= 36, a perfect startboost is awarded.

If > 36 and <= 50, a normal startboost is awarded.

If > 50, the engine bursts and the player is left without control for a few seconds.

k_jmp Short for "jump", from when pressing Drift made the kart jump. Determines if the drift button is held when drifting, in which case the value is 1.
k_offroad Offroad timer, used to check for offroad leniency before slowing the Player down.
k_pogospring Pogo Spring state. (Removed when on the ground). This makes the Player's frameangle increment, lets them steer and Accelerate in mid-air and increases their gravity.

This state is also removed if the Player is to bump a wall.

k_brakestop Timer used to make sure braking doesn't instantly make the Player go in reverse after you've stopped
k_waterskip Counts how many times the Player has waterskipped in a single go
k_dashpadcooldown Used as a timer to make sure Dash Pads (not to be mistaken with Boost Pads, we are here talking about the likes of Twinkle Circuit's Dash Pads) don't repeat themselves. In vanilla, player.powers[pw_flashing] was used instead.
k_boostpower Affects player's top speed, while also acting as a multiplier for player.kartstuff[k_speedboost] and player.kartstuff[k_accelboost].

A value of FRACUNIT is neutral and doesn't do anything, 3*FRACUNIT/2 increases the Player's top speed by 50% and multiplies player.kartstuff[k_speedboost] and player.kartstuff[k_accelboost] values by 1.5, and 4*FRACUNIT/5 (often assigned in offroad sectors) decreases the Player's top speed by 20% and multiplies player.kartstuff[k_speedboost] and player.kartstuff[k_accelboost] values by 0.8.

k_speedboost Used to increment or decrement the Player's max speed.

A value of 0 is neutral and doesn't do anything, a value of FRACUNIT/2 increases the Player's top speed by 50%, a value of -FRACUNIT/3 reduces the Player's top speed by 33%. Internally, this is used for Sneaker Boosts (as well as all other boosts) and uses player.kartstuff[k_boostpower] as a modifier.

k_accelboost Functions similarly to player.kartstuff[k_speedboost] but affects the Player's acceleration instead of their max speed.
k_boostangle When spun out, used to determine what angle Boost Pads should send you at. This is updated When the Player isn't spun out, or is under the effect of a Boost Pad.
k_boostcam Used for the Diddy Kong Racing camera-like effect when Boosting.
k_boostcamdest Used for the Diddy Kong Racing camera-like effect when Boosting.
k_timeovercam Determines what the camera should do after the Player has no contested.
k_aizdriftstrat Used for sliptide particle spawning, -1 is for a Right turn and 1 for a Left turn.
k_brakedrift Used to spawn the sparks when brake-drifting.
k_itemroulette Timer that determines when you should get an item after popping a Random Item Box.

Unlike most other timers, this one increments until it reaches the value of TICRATE*3 which is when the item is awarded to the Player.

k_roulettetype Used to determine what roulette to use, if set to 1, the item roulette will have increased odds of strong items. Currently only used for Karma items in Battle Mode.
k_itemtype KITEM_ constant of the item held by the Player.
k_itemamount How many items the player is holding. In normal gameplay, this cannot go above 255.
k_itemheld Used to know if the Player is dragging an item behind them.
k_curshield The Player's current Shield.

0 = No Shield

1 = Thunder Shield

k_hyudorotimer Timer for Hyudoro intangibility and offroad immunity
k_sneakertimer Timer for Sneaker and Rocket Sneaker boosting
k_stealingtimer Timer to flash the HUD item as the Player is stealing an item
k_stolentimer Timer to flash the HUD item as the Player is being stolen from
k_growshrinktimer Shrink if < 0, Grow if > 0, Normal Size if == 0
k_squishedtimer Timer for being squished. The Player is unable to move that duration
k_rocketsneakertimer Timer for how long Rocket Sneakers can still be held for. This decrements over time, and more so when the item is being used for boosting.
k_invincibilitytimer Timer for how long the Player can remain invincible for still
k_eggmanheld Holding an Eggman item out. Separate from k_itemheld as doing this does not prevent you from getting another item.
k_eggmanexplode Player has picked up an Eggman Item, this is their timer until they explode.
k_eggmanblame Player number of the Player who planted the Eggman Item. You can retrieve said player with players[player.kartstuff[k_eggmanblame]]

Internally used to know what color the explosion should be

k_lastjawztarget Last Player number targetted by a Jawz the Player is holding out. Used to prevent the targetting sound from repeating itself.
k_bananadrag Timer used to determine when to start slowing the Player down for holding an item out for too long. This is reset each time an item is thrown, should there be more than a single trailing item
k_spinouttimer Timer for being Spun Out. During Spin Out, the Player will keep sliding forward until they hit a minimum speed at which they will keep sliding at. This is set by Bananas and stage hazards.
k_wipeoutslow Timer for being Wiped Out. Set by Orbinauts, Jawz, or being bumped whilst Spun Out. This will drastically slow the Player down until they hit a standstill.

You can tell the Wipe Out state apart from Spin Out from the dust particles spawning during Wipe Out as well.

k_justbumped Used to prevent two Players from endlessly bumping each other should they be inside each other for some reason.
k_comebacktimer In Battle Mode, keeps track of how long you've been a Bomb/Karma Item for
k_sadtimer Only used internally for bugged items which default back to a sad smiley face which sets this timer upon being used.
k_bumper Number of Battle Bumpers left on the Player
k_comebackpoints Number of Points scored in Comeback Mode.
k_comebackmode Player's Comeback Mode: 0 = Bomb, 1 = Item
k_wanted If this value is high enough, the Player becomes wanted. This value lowers when the Player hits other Players. The intent is for Players running away for too long to become targetted.
k_yougotem HUD timer for "You got em" upon bombing a Wanted Player in Comeback Mode
k_itemblinkmode Determines what color and sound are used upon getting an item,

0 = White (Normal)

1 = Red (Mashing)

2 = Rainbow (Karma)

k_getsparks Disables drift sparks at low speed to prevent heavy characters from having an easier time recovering
k_jawztargetdelay Timer to prevent jawz from switching targets too fast
k_spectatewait Timer to keep track as to how long a Player has been a spectator for
k_growcancel How long the item button has been held for to cancel the Player's Growth

ticcmd_t

This userdata type represents a player's current button information, i.e., what buttons are being pressed currently. In the examples below, cmd is used as the name of the ticcmd_t variable. An access to a variable var of ticcmd_t is written as cmd.var.

General
Accessibility Read+Write
Allows custom variables No
ticcmd_t structure
Name Type Accessibility Description/Notes
forwardmove SINT8 Read+Write Value related to forwards/backwards buttons; positive values move the player forward, negative values move the player backwards. Ranges from -50 to 50.
sidemove SINT8 Read+Write Value related to strafe left/right buttons; positive values move the player right, negative values move the player left. Ranges from -50 to 50.

While still present in the structure, this is actually unused in SRB2Kart

angleturn INT16 Read+Write Value related to turn left/right buttons; to use as angle_t this needs to be shifted up by 16 bits (cmd.angleturn<<16 or cmd.angleturn*65536).
driftturn INT16 Read+Write Value related to drifting left and right. Is always between -800 and 799.
aiming INT16 Read+Write Value related to look up/down buttons; to use as angle_t this needs to be shifted up by 16 bits (cmd.aiming<<16 or cmd.aiming*65536).
buttons UINT16 Read+Write Contains flags representing buttons currently pressed (BT_* constants should be used).
latency UINT8 Read+Write Player's latency in number of frames. Added to the sartboost timer's value to make sure Ping doesn't affect the timing.

skin_t

This userdata type represents the properties of a character skin, which are defined in a character's S_SKIN lump. In the examples below, skin is used as the name of the skin_t variable. An access to a variable var of skin_t is written as skin.var.

General
Accessibility Read-only
Allows custom variables No
# (Length) #skin → skin number
#skin.soundsid → total number of skin sounds (21)
skin_t structure
Name Type Accessibility Description/Notes
valid boolean Read-only Returns true if the skin is valid (i.e., it exists), false if not.
name string Read-only Returns the internal name string for the skin set by the S_SKIN (e.g., skins["sonic"].name would return "sonic").
spritedef N/A None Unusable by Lua – not yet implemented
wadnum N/A None Unusable by Lua – not network safe, may differ between clients due to music wads
flags enum (SF_*) Read-only Returns the flags given to the skin by the S_SKIN.
realname string Read-only Returns the displayed name string for the skin set by the S_SKIN (e.g., skins["sonic"].realname would return "Sonic").
hudname string Read-only Returns the HUD name string for the skin set by the S_SKIN (e.g., skins["knuckles"].hudname would return "K.T.E").
facerank string Read-only Returns the name for the rank icon graphic of the Skin (e.g., skins["sonic"].facerank would return "PLAYRANK").
facewant string Read-only Returns the name for the Wanted icon graphic of the Skin (e.g., skins["sonic"].facewant would return "PLAYWANT").
facemmap string Read-only Returns the name for the Mini-map icon graphic of the Skin (e.g., skins["sonic"].facemmap would return "PLAYMMAP").
kartspeed UINT8 Read-only Returns the Skin's kart Speed stat.
kartweight UINT8 Read-only Returns the Skin's kart Weight stat.
starttranscolor UINT8 Read-only Returns the starting palette color # for the changeable 16-color range for the skin set by the S_SKIN (startcolor).
prefcolor UINT8 Read-only Returns the default skincolor for use in Single player for the skin set by the S_SKIN. (see SKINCOLOR_* constants)
highresscale fixed_t Read-only Returns the relative scale to display sprites at for the skin set by the S_SKIN (this will be the S_SKIN's value multiplied by FRACUNIT).
soundsid[SKSNAME] enum (sfx_*) array Read-only A table containing all of the corresponding sound numbers for all skinsound slots for the skin, where SKSNAME is an integer that is expected to be one of the SKS* constants. For example, skins["sonic"].soundsid[SKSTHOK] returns sfx_thok, the default sound for the SKSTHOK skinsound slot; for custom characters who may have a custom sound set for any of the skin sounds, this returns the sound number for the custom sound instead.

SOC

These userdata types represent components of the game that can also be modified by SOC.

mobjinfo_t

See also: Object > Object type attributes

This userdata type represents the properties of an Object type. In the examples below, info is used as the name of the mobjinfo_t variable. An access to a variable var of mobjinfo_t is written as info.var.

General
Accessibility Read+Write
Allows custom variables Yes
# (Length) #info → Object type number
mobjinfo_t structure
Name Type Accessibility Description/Notes
doomednum INT32 Read+Write MapThingNum: The Thing type number, should be a number between 1 and 4095. If set to -1, the Object type cannot be placed through Things on the map.
spawnstate enum (S_*) Read+Write SpawnState: The state that this type of Object calls when it is spawned. Its duration may not be 0. If the SpawnState has an action, it will not be performed when the Object is first spawned unless the MF_RUNSPAWNFUNC flag is set on the Object. If the SpawnState is called again after that, however, the action will be performed even without the flag.
spawnhealth INT32 Read+Write SpawnHealth: The initial value for the health variable for mobj_t.
seestate enum (S_*) Read+Write SeeState: Called once an Object spots a player, which can be done with the action A_Look and certain actions that are made specifically for some of SRB2's specific enemies.
seesound enum (sfx_*) Read+Write SeeSound: Usually played when the SeeState is executed. A_PlaySeeSound is made specifically to call this sound.
reactiontime INT32 Read+Write ReactionTime: The initial value for the reactiontime variable for mobj_t.
attacksound enum (sfx_*) Read+Write AttackSound: Usually played by certain attack actions for enemies. The action A_PlayAttackSound is made specifically to call this sound.
painstate enum (S_*) Read+Write PainState: The state that Objects with the flag MF_SHOOTABLE go to when they are damaged but not yet dead.
painchance INT32 Read+Write PainChance: Used for miscellaneous purposes and will be unused for most Objects.
painsound enum (sfx_*) Read+Write PainSound: Usually played when the PainState is executed. The action A_Pain is made specifically to call this sound.
meleestate enum (S_*) Read+Write MeleeState: The first of two attack states. Actions call this or MissileState when the Object should attack.
missilestate enum (S_*) Read+Write MissileState: The second of two attack states. Actions call this or MeleeState when the Object should attack.
deathstate enum (S_*) Read+Write DeathState: The state that Objects go to when they are destroyed, i.e., have no health points left. For regular enemies, this sequence of states should eventually point to S_NULL, which is used for Objects that have disappeared.
xdeathstate enum (S_*) Read+Write XDeathState: Usually used as the fleeing state for bosses. It is called by the action A_BossDeath.
deathsound enum (sfx_*) Read+Write DeathSound: Usually played when the DeathState is executed. The action A_Scream is made specifically to call this sound.
speed fixed_t Read+Write Speed: Usage depends on situation; can be just a regular number in some cases, other cases this needs to be a multiple of FRACUNIT
radius fixed_t Read+Write Radius: The initial value for the radius variable for mobj_t. This may also be referenced when an Object's scale is modified.
height fixed_t Read+Write Height: The initial value for the height variable for mobj_t. This may also be referenced when an Object's scale is modified.
dispoffset INT32 Read+Write DispOffset: Used to resolve ordering conflicts when drawing sprites that are in the same position in Software rendering. Sprites with a higher display offset are always drawn in front of sprites with a lower display offset. For instance, the shield orbs all have this set to 1, which means they are always displayed in front of the player when both are in the exact same position. Any integer value can be used here, including negative values; SRB2's Objects only use values up to 2, so anything above that will make the Object take precedence over all of SRB2's default Objects. For most Objects, this can be set to 0.
mass INT32 Read+Write Mass: Used for miscellaneous purposes and will be unused for most Objects. It has no relation to the heaviness of an Object.
damage INT32 Read+Write Damage: Used for miscellaneous purposes and will be unused for most Objects.
activesound enum (sfx_*) Read+Write ActiveSound: Used for miscellaneous sounds that are part of an Object's animation. A_PlayActiveSound is made specifically to call this sound.
flags INT32 Read+Write Flags: The initial value given to the flags variable for mobj_t. (Use MF_* constants)
raisestate enum (S_*) Read+Write RaiseState: Used for miscellaneous purposes. For example, A_ShootBullet, A_DropMine and A_JetgShoot all spawn Objects with this state.

state_t

See also: State > Attributes

This userdata type represents the properties of a state. In the examples below, state is used as the name of the state_t variable. An access to a variable var of state_t is written as state.var.

General
Accessibility Read+Write
Allows custom variables No
# (Length) #state → State number
state_t structure
Name Type Accessibility Description/Notes
sprite enum (SPR_*) Read+Write SpriteName: Sprite prefix number used for the state.
frame UINT32 Read+Write SpriteFrame: Frame number of the sprite used for the state; also contains full brightness/translucency information. (See tr_* and FF_* constants)
tics INT32 Read+Write Duration: Duration of the state, in tics. -1 is infinite, 0 is instantaneous.
action function Read+Write Action: The action used by the state, run when an Object switches to the state. Can be set to a pre-existing action, or a custom one created using Lua, or be just nil if none is set. The return value is the function the action calls.
var1 INT32 Read+Write Var1: The Var1 value built-in to be used by state.action, when an Object first switches to the state.
var2 INT32 Read+Write Var2: The Var2 value built-in to be used by state.action, when an Object first switches to the state
nextstate enum (S_*) Read+Write Next: The next state number to go to after the state has finished being used. A state.nextstate of S_NULL will make the Object using the current state be removed from the map when about to switch to the new state.

sfxinfo_t

See also: Sound > Attributes

This userdata type represents the properties of a sound. In the examples below, info is used as the name of the sfxinfo_t variable. An access to a variable var of sfxinfo_t is written as info.var.

General
Accessibility Read+Write
Allows custom variables No
# (Length) #info → Sound number
sfxinfo_t structure
Name Type Accessibility Description/Notes
name string Read-only The name of the sound following the sfx_ prefix, e.g., S_sfx[sfx_thok].name would return "thok".
singular boolean Read+Write Singular: Determines whether only one of the sound can be played at a time (true) or not (false).
priority INT32 Read+Write Priority: The priority of the sound, i.e., this determines how important it is to play this sound; if a sound with a higher priority is playing this sound will be drowned out, otherwise if vice versa this sound will drown out the other instead. Usually a value between 0 and 255.
flags INT32 Read+Write Flags: (Known as "pitch" in the source code) Sets/returns the sound flags set for the sound. (use SF_* constants, not to be confused with skin flags)
skinsound INT32 Read-only Skin sound id number; for sounds that are not changable by the skin this will be -1. (See SKS* constants)

hudinfo_t

See also: Heads-up display > HUD item modification

This userdata type represents the properties of a HUD item. In the examples below, info is used as the name of the hudinfo_t variable. An access to a variable var of hudinfo_t is written as info.var.

General
Accessibility Read+Write
Allows custom variables No
# (Length) #info → HUD item number
hudinfo_t structure
Name Type Accessibility Description/Notes
x INT32 Read+Write X coordinate of the HUD item (from the left of the screen). Should be a value between 0 and 320.
y INT32 Read+Write Y coordinate of the HUD item (from the top of the screen). Should be a value between 0 and 200.

mapheader_t

This userdata type represents the properties of a level header. In the examples below, mapheader is used as the name of the mapheader_t variable. An access to a variable var of mapheader_t is written as mapheader.var.

General
Accessibility Read-only
Allows custom variables SOC-only
# (Length) #mapheader → Map number
mapheader_t structure
Name Type Accessibility Description/Notes
lvlttl string Read-only LevelName
subttl string Read-only SubTitle
zonttl string Read-only String to display instead of "ZONE"
actnum string Read-only Act number. Although it can also be letters
typeoflevel UINT16 Read-only TypeOfLevel, as a set of flags stored in an integer. See TOL_* constants.
nextlevel INT16 Read-only NextLevel, as an integer.
musname string Read-only Music
mustrack UINT16 Read-only MusicTrack
muspos UINT32 Read-only MusicPos
musinterfadeout UINT32 Read-only MusicInterFadeOut
musintername string Read-only MusicInter
forcecharacter string Read-only ForceCharacter
weather UINT8 Read-only Weather. See PRECIP_* constants.
skynum INT16 Read-only SkyNum
skybox_scalex INT16 Read-only SkyboxScaleX
skybox_scaley INT16 Read-only SkyboxScaleY
skybox_scalez INT16 Read-only SkyboxScaleZ
interscreen string Read-only InterScreen
runsoc string Read-only RunSOC
scriptname string Read-only ScriptName
precutscenenum UINT8 Read-only PreCutsceneNum
cutscenenum UINT8 Read-only CutsceneNum
countdown INT16 Read-only Countdown
palette UINT16 Read-only Palette
numlaps UINT8 Read-only NumLaps
unlockrequired SINT8 Read-only Unlockable minus 1:
  • -1 = no unlockable required
  • 0 = unlockable #1 required
  • etc.
levelselect UINT8 Read-only LevelSelect
bonustype SINT8 Read-only BonusType:
  • -1 = None
  • 0 = Normal
  • 1 = Boss
  • 2 = ERZ3

(UNUSED)

saveoverride SINT8 Read-only SaveOverride. See SAVE_* constants. (UNUSUED)
levelflags UINT8 Read-only LevelFlags. See LF_* constants.
menuflags UINT8 Read-only MenuFlags. See LF2_* constants.
mobj_scale fixed_t Read-only Global Object Scale on the map. FRACUNITis the default value

Map

These userdata types represent components of the the game that are part of a map.

mapthing_t

This userdata type represents a map Thing. In the examples below, mapthing is used as the name of the mapthing_t variable. An access to a variable var of mapthing_t is written as mapthing.var.

General
Accessibility Read+Write
Allows custom variables No
mapthing_t structure
Name Type Accessibility Description/Notes
valid boolean Read-only Returns true if the Thing is valid (i.e., it exists), false if not.
x INT16 Read+Write The X coordinate of the Thing in the map, in fracunits.
y INT16 Read+Write The Y coordinate of the Thing in the map, in fracunits.
angle INT16 Read+Write The angle the map Thing is facing, in degrees. For most purposes, this is a value from 0 to 359 – 0 is East, 90 is North, 180 is West and 270 is South. However, some Object types use this variable for other purposes; in these cases, it can be any value from -32768 to 32767.
type UINT16 Read+Write The map Thing number of the Object (or otherwise) to spawn with the map Thing. Does not include the multiples of 4096 added on by the map (see mapthing.extrainfo).
options UINT16 Read+Write The flags for the map Thing (see MTF_* constants). Also contains Z position information, shifted up by 4 bits (options = flags + z<<4).
z INT16 Read+Write The Z position of the map Thing above the sector floor, in fracunits. Usually pre-calculated by the game as mapthing.options>>4.
extrainfo UINT8 Read+Write An extra parameter calculated as the number of multiples of 4096 added onto the map Thing number. Used by a few Object types for extra effects.
mobj mobj_t Read+Write Points to the Object spawned by the map Thing. This is not set for Thing types that have no corresponding Object type, such as special placement patterns. In these cases, the value of mobj is nil.

sector_t

This userdata type represents a sector. In the examples below, sector is used as the name of the sector_t variable. An access to a variable var of sector_t is written as sector.var.

General
Accessibility Read+Write
Allows custom variables No
# (Length) #sector → Sector number
#sector.lines → Number of linedefs belonging to sector
sector_t structure
Name Type Accessibility Description/Notes
valid boolean Read-only Returns true if the sector is valid (i.e., it exists), false if not.
floorheight fixed_t Read+Write The absolute height of the sector's floor in the map.
ceilingheight fixed_t Read+Write The absolute height of the sector's ceiling in the map.
floorpic string Read+Write The name of the sector's floor flat.
ceilingpic string Read+Write The name of the sector's ceiling flat.
lightlevel INT16 Read+Write The brightness level of the sector. This should be a value between 0 and 255.
special INT16 Read+Write The total of the sector's sector special values in all 4 sections given to the sector (section1 + section2<<4 + section3<<8 + section4<<12). Use GetSecSpecial(sector.special, n) to get the sector special set in a particular section n.
tag INT16 Read+Write The tag of the sector. Due to the way this is set up, all tags from 32768 to 65535 (seen when using map editors) are in fact -32768 to -1, although either can be used for assigning a new tag value (it will be automatically converted to the latter version anyway). Changing the value of sector.tag will have the same effect as changing it with Linedef type 409 or Linedef type 410.
thinglist() function Read-only To be used in an iterator function, e.g., for mobj in sector.thinglist(). This iterates through all the Objects within the sector, returning a mobj_t variable for use within the loop's contents.
heightsec sector_t Userdata: Read-only
Userdata variables: Read+Write
The control sector for a sector's Fake Floor/Ceiling Planes linedef special, if one exists.
camsec sector_t Userdata: Read-only
Userdata variables: Read+Write
The control sector for a sector's camera clipping heights, if one exists – this is set by combining the Special Sector Properties linedef special with the Intangible to the Camera sector special in the linedef's front sector.
lines[i] line_t array Read-only A table storing all the sector's linedefs.
ffloors() function Read-only To be used in an iterator function, e.g., for rover in sector.ffloors(). This iterates through all the FOFs within the sector, returning a ffloor_t variable for use within the loop's contents.
f_slope pslope_t Read-only The sector's floor slope. This is nil if no floor slope is set.
c_slope pslope_t Read-only The sector's ceiling slope. This is nil if no ceiling slope is set.

subsector_t

This userdata type represents a subsector. In the examples below, subsector is used as the name of the subsector_t variable. An access to a variable var of subsector_t is written as subsector.var.

General
Accessibility Read-only
Allows custom variables No
# (Length) #subsector → Subsector number
subsector_t structure
Name Type Accessibility Description/Notes
valid boolean Read-only Returns true if the subsector is valid (i.e., it exists), false if not.
sector sector_t Userdata: Read-only
Userdata variables: Read+Write
Points to the sector this subsector is linked to.
numlines INT16 Read-only A variable used internally to get the number of segs within this subsector.
firstline UINT16 Read-only A variable used internally to get the number of the first seg within this subsector.

line_t

This userdata type represents a linedef. In the examples below, line is used as the name of the line_t variable. An access to a variable var of line_t is written as line.var.

General
Accessibility Read-only
Allows custom variables No
# (Length) #line → Linedef number
line_t structure
Name Type Accessibility Description/Notes
valid boolean Read-only Returns true if the linedef is valid (i.e., it exists), false if not.
v1 vertex_t Read-only Points to the first of the two vertices the linedef is connected to.
v2 vertex_t Read-only Points to the second of the two vertices the linedef is connected to.
dx fixed_t Read-only Pre-calculated distance between the linedef's two vertex X coordinates (line.v2.x-line.v1.x).
dy fixed_t Read-only Pre-calculated distance between the linedef's two vertex Y coordinates (line.v2.y-line.v1.y).
flags INT16 Read-only Contains the linedef flags for the linedef (see ML_* constants).
special INT16 Read-only The linedef's linedef type number.
tag INT16 Read-only The tag number set for the linedef. Due to the way this is set up, all tags from 32768 to 65535 (seen when using map editors) are in fact -32768 to -1, although either can be used for assigning a new tag value (it will be automatically converted to the latter version anyway).
sidenum[i] UINT16 array Read-only This is a small table containing the sidedef numbers for both the front sidedef (line.sidenum[0]) and the back sidedef if one exists (line.sidenum[1]). To get the sidedef userdata for these, use sides[line.sidenum[i]], i being either 0 (front) or 1 (back). To check if either sidedef is valid, use line.sidenum[i].valid, which will return either true or false.
frontside side_t Read-only Points to the linedef's front sidedef (same as sides[line.sidenum[0]]).
backside side_t Read-only Points to the linedef's back sidedef, if it exists (same as sides[line.sidenum[1]]); this will return nil if not.
slopetype string Read-only A string representing the linedef's orientation in the map:
  • "horizontal": directly horizontal (line.dy is 0)
  • "vertical": directly vertical (line.dx is 0)
  • "positive": gradient is positive (line.dy/line.dx > 0)
  • "negative": gradient is negative (line.dy/line.dx < 0)
frontsector sector_t Userdata: Read-only
Userdata variables: Read+Write
Points to the linedef's front sector.
backsector sector_t Userdata: Read-only
Userdata variables: Read+Write
Points to the linedef's back sector, if it exists.
firsttag INT16 Read-only A variable used internally by functions that search for linedefs by tag.
nexttag INT16 Read-only A variable used internally by functions that search for linedefs by tag.
text string Read-only Concatenation of all front and back texture name strings, for linedef types that require text in any of them.
callcount INT16 Read-only

side_t

This userdata type represents a sidedef. In the examples below, side is used as the name of the side_t variable. An access to a variable var of side_t is written as side.var.

General
Accessibility Read+Write
Allows custom variables No
# (Length) #side → Sidedef number
side_t structure
Name Type Accessibility Description/Notes
valid boolean Read-only Returns true if the sidedef is valid (i.e., it exists), false if not.
textureoffset fixed_t Read+Write The sidedef's X texture offset (negative is to the left, positive is to the right).
rowoffset fixed_t Read+Write The sidedef's Y texture offset (negative is downwards, positive is upwards).
toptexture INT32 Read+Write The sidedef's upper texture number. This is 0 if no valid texture is set. See List of textures by number for the numbers of SRB2's textures.
bottomtexture INT32 Read+Write The sidedef's lower texture number. This is 0 if no valid texture is set. See List of textures by number for the numbers of SRB2's textures.
midtexture INT32 Read+Write The sidedef's middle texture number. This is 0 if no valid texture is set. See List of textures by number for the numbers of SRB2's textures.
sector sector_t Userdata: Read-only
Userdata variables: Read+Write
Points to the sector the sidedef is facing.
special INT16 Read-only The linedef type special of the linedef the sidedef belongs to.
repeatcnt INT16 Read+Write The number of times to repeat the sidedef's middle texture.
text string Read-only Concatenation of the upper, middle and lower texture name strings, for linedef types that require text in any of them.

vertex_t

This userdata type represents a vertex. In the examples below, vertex is used as the name of the vertex_t variable. An access to a variable var of vertex_t is written as vertex.var.

General
Accessibility Read-only
Allows custom variables No
# (Length) #vertex → Vertex number
vertex_t structure
Name Type Accessibility Description/Notes
valid boolean Read-only Returns true if the vertex is valid (i.e., it exists), false if not.
x fixed_t Read-only The absolute X coordinate of the vertex in the map.
y fixed_t Read-only The absolute Y coordinate of the vertex in the map.
z fixed_t Read-only Used as an absolute Z coordinate in some special cases, but for all Lua purposes this is unused.

ffloor_t

This userdata type represents an FOF.

General
Accessibility Read+Write
Allows custom variables No
ffloor_t structure
Name Type Accessibility Description/Notes
valid boolean Read-only Returns true if the FOF is valid (i.e., it exists), false if not.
topheight fixed_t Read+Write The absolute Z position of the FOF's top surface in the map. Modifying this will also modify the ceiling height of the FOF's control sector at the same time.
toppic string Read+Write The name of the FOF's top surface flat. Modifying this will also modify the ceiling flat of the FOF's control sector at the same time.
toplightlevel INT16 Read+Write The brightness level of the FOF. This should be a value between 0 and 255. Modifying this will also modify the brightness level of the FOF's control sector at the same time.
bottomheight fixed_t Read+Write The absolute Z position of the FOF's bottom surface in the map. Modifying this will also modify the floor height of the FOF's control sector at the same time.
bottompic string Read+Write The name of the FOF's bottom surface flat. Modifying this will also modify the floor flat of the FOF's control sector at the same time.
t_slope pslope_t Read-only The FOF's top slope. This is nil if no top slope is set.
b_slope pslope_t Read-only The FOF's bottom slope. This is nil if no bottom slope is set.
sector sector_t Userdata: Read-only
Userdata variables: Read+Write
The FOF's control sector.
flags enum (FF_*) Read+Write The FOF's flags.
master line_t Read-only The FOF's control linedef.
target sector_t Userdata: Read-only
Userdata variables: Read+Write
The target sector the FOF is located in.
next ffloor_t Userdata: Read-only
Userdata variables: Read+Write
The next FOF in the target sector's FOF list. This is nil if the FOF is the last in the list.
prev ffloor_t Userdata: Read-only
Userdata variables: Read+Write
The previous FOF in the target sector's FOF list. This is nil if the FOF is the first in the list.
alpha INT32 Read+Write The FOF's alpha/translucency value. This should be a value between 1 and 256.

pslope_t

This userdata type represents a slope. In the examples below, slope is used as the name of the pslope_t variable. An access to a variable var of pslope_t is written as slope.var.

General
Accessibility Read+Write
Allows custom variables No
pslope_t structure
Name Type Accessibility Description/Notes
valid boolean Read-only Returns true if the slope is valid (i.e., it exists), false if not.
o vector3_t Userdata: Read+Write
Userdata variables: Read-only
The slope's origin vector.

For sector-based slopes, the origin's X/Y position is placed a fixed horizontal distance (known as the "extent" internally) away from the middle point of the linedef that defines the slope, at an angle of xydistance. The Z position is set as the un-sloped height of the floor or ceiling plane the slope is created for.

Currently, the only way to modify this variable is by assigning to it a custom table with x, y and z fields, such as below:

slope.o = {"x" = 1*FRACUNIT, "y" = 2*FRACUNIT, "z" = 3*FRACUNIT} -- change the origin's position to (1, 2, 3)

Unless SL_NODYNAMIC is set in the slope's flags, the origin's Z position (slope.o.z) will be automatically corrected accordingly with the sector heights or vertices used to create the slope. This means that slope.o.z cannot be modified by Lua unless the flag is not set.

d vector2_t Read-only The slope's 2D (X,Y) direction vector. Used to determine distance from the origin in 2D mapspace. The values are normalised, i.e.: they are equivalent to a thrust of FRACUNIT, though in the opposite direction to the angle xydirection.
zdelta fixed_t Read+Write The rate at which Z changes based on distance from the origin.

For sector-based slopes, this is calculated as the un-sloped height of the sector plane on the other side of the linedef that defines the slope's plane, minus the un-sloped height of the slope's own plane, and divided by the slope's "extent" value (see o for explanation). (i.e.: zdelta = (plane2-plane1)/ extent)

Unless SL_NODYNAMIC is set in the slope's flags, this value will be automatically corrected accordingly with the sector heights or vertices used to create the slope. This means that this value cannot be modified by Lua unless the flag is not set. Otherwise, modifying this value will also automatically update zangle and normal accordingly.

normal vector3_t Read-only The normal vector of the slope's plane. It was intended to point upward out of the plane, but it instead follows the direction of it (only true for sector slopes?[confirm? – discuss]). Currently unused.

Unless SL_NODYNAMIC is set in the slope's flags, this value will be automatically corrected accordingly with the sector heights or vertices used to create the slope.

zangle fixed_t Read+Write The vertical angle of the slope's plane, going up from the ground (i.e. a "flat" slope plane would have a zangle of 0).

Unless SL_NODYNAMIC is set in the slope's flags, this value will be automatically corrected accordingly with the sector heights or vertices used to create the slope. This means that this value cannot be modified by Lua unless the flag is not set. Otherwise, modifying this value will also automatically update zdelta and normal accordingly.

ANGLE_90 and ANGLE_270 are not accepted as values for this variable; the game will print an error message if you attempt to assign them to it.

xydirection angle_t Read+Write The horizontal angle of the slope's plane.

Modifying this value will also automatically update d and normal accordingly.

sourceline line_t Read-only The linedef used to generate the slope.
refpos UINT8 Read-only Indicates the type of slope, for dynamic slopes:
  • 1 – Front floor
  • 2 – Front ceiling
  • 3 – Back floor
  • 4 – Back ceiling
  • 5 – Vertex slope
flags UINT8 Read-only The slope's flags (see SL_* constants).

Miscellaneous

These userdata types represent components of the game that do not fit into the above groups.

camera_t

This userdata type represents a player's camera. In the examples below, camera is used as the name of the camera_t variable. An access to a variable var of camera_t is written as camera.var.

General
Accessibility Read-only
Allows custom variables No
camera_t structure
Name Type Accessibility Description/Notes
chase boolean Read-only Returns true if the third-person camera is enabled, false if not.
aiming angle_t Read-only The vertical viewing angle of the camera.
x fixed_t Read-only The camera's absolute X position in the map.
y fixed_t Read-only The camera's absolute Y position in the map.
z fixed_t Read-only The camera's absolute Z position in the map.
angle angle_t Read-only The absolute angle the camera is facing. 0 is East, ANGLE_90 is North, ANGLE_180 is West, and ANGLE_270 is South.
subsector subsector_t Read-only The subsector the camera is currently in. To obtain the sector the camera is in, use camera.subsector.sector.
floorz fixed_t Read-only The absolute "floor" position for the camera, i.e., the height that it considers to be the floor. This can be different from the floor height of the sector the camera is in, for example if it is above a solid FOF.
ceilingz fixed_t Read-only The absolute "ceiling" position for the camera, i.e., the height that it considers to be the ceiling. This can be different from the ceiling height of the sector the camera is in, for example if it is below a solid FOF.
radius fixed_t Read-only The current radius of the camera. By default this is 20*FRACUNIT, but it will automatically scale along with the corresponding player's scale.
height fixed_t Read-only The current height of the camera. By default this is 16*FRACUNIT, but it will automatically scale along with the corresponding player's scale.
momx fixed_t Read-only The camera's current X-axis momentum. Positive values shift the camera to the East, negative values to the West.
momy fixed_t Read-only The camera's current Y-axis momentum. Positive values shift the camera to the North, negative values to the South.
momz fixed_t Read-only The camera's current Z-axis momentum. Positive values shift the camera upwards, negative values downwards.

consvar_t

This userdata type represents a console variable.

General
Accessibility Read-only
Allows custom variables No
consvar_t structure
Name Type Accessibility Description/Notes
name string Read-only The name of the console variable, as it should be written in the console.
defaultvalue string Read-only The default value set for the console variable, expressed as a string.
flags INT32 Read-only Contains the flags set for the console variable (see CV_* constants).
value INT32 Read-only The current value set for the console variable, expressed as a number.
string string Read-only The current value set for the console variable, expressed as a string.
changed boolean Read-only Returns whether the console variable has been changed by the player (true) or not (false).

patch_t

This userdata type allows access to the properties of a graphics patch (see the HUD library).

General
Accessibility Read-only
Allows custom variables No
patch_t structure
Name Type Accessibility Description/Notes
valid boolean Read-only Returns true if the patch is valid (i.e., it exists), false if not.
width INT16 Read-only The width of the patch, in fracunits/pixels.
height INT16 Read-only The height of the patch, in fracunits/pixels.
leftoffset INT16 Read-only The X offset of the patch (positive is left, negative is right), in fracunits/pixels.
topoffset INT16 Read-only The Y offset of the patch (positive is down, negative is up), in fracunits/pixels.
  Lua [view]
Language features SyntaxMetatables
SRB2 data ActionsConstantsFunctionsGlobal variablesHooksUserdata structures
SRB2Kart data Kart Userdata structuresKart FunctionsKart HooksKart Global Variables and Constants
Tutorials Freeslots and Object resourcesCustom player ability