Category:Gamevar manipulation: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
Jwaffe (talk | contribs)
m added note that DEFAULT isn't used
→‎Gamevar Flags: Updated gamevar flag list to current information taken from source code definitions and comments. It seems to be possible to assign, for instance, the read-only flag to user-defined gamevars, so contrary to what the page stated, flags > 2 can be assigned in CON
(One intermediate revision by the same user not shown)
Line 1: Line 1:
== Definition ==
'''gamevar''' <varname> <value> <flags>
'''gamevar''' <varname> <value> <flags>


A gamevar is a game variable that can be used to store numerical data which can then be referenced between [[actor]]s.
'''var''' <varname> <value> <flags>


A gamevar's flags determine how it is referenced by the game.  A gamevar with flags of 0 is known as a global variable.  A global variable exists once in the code, and any time a global variable is set, the new value is seen by all [[actor]]s.  A gamevar with flags of 1 is a per-player variable.  Per-player variables exist once per player in the game, with each player having their own copy of the variable.  A gamevar with flags of 2 is a per-[[actor]] variable.  A per-[[actor]] variable exists as many times in the code as there are [[sprite]]s in the map. Each [[sprite]] has its own copy of a per-[[actor]] variable in memory.
A gamevar is a variable that can be used to store numerical data which can then be referenced between [[actor]]s, [[state]]s and [[event]]s. '''var''' is hereby semantically equivalent to '''gamevar'''.


A gamevar value has a range of -2147483648 (-2<sup>31</sup>) to 2147483647 (2<sup>31</sup>-1), also known as a signed 32-bit integer.
The gamevar's flags define a bitmap that determines how the variable is treated by the game. For instance, a gamevar with flags of 0 is known as a global variable.  A global variable exists once in the code, and any time a global variable is set, the new value is seen by all [[actor]]s and [[event]]s.  A gamevar with flag bit 1 set is a per-player variable, which exists once for each player in the game.  A gamevar with flag bit 2 set is a per-[[actor]] variable, which exists as many times in the code as there are [[sprite]]s in the map.  This means that each [[sprite]] has its own copy of a per-[[actor]] variable stored in memory. '''Note that a gamevar can only be defined as either global, per-player, or per-actor, but not as a combination thereof.'''


Gamevars are stored as '''signed 32-bit integers''' and therefore have a value range of ''-2.147.483.648 (-2<sup>31</sup>)'' to ''2.147.483.647 (2<sup>31</sup>-1)''. Going above and below this range causes the value to overflow and underflow respectively.
Note that it is possible to omit the <value> and <flags> parameters entirely to define a global variable with an initial value of 0, with no other flags set. Example:
var TEMP1
It is also possible to chain flags separately at the end of the gamevar definition, instead of compiling them into a single value, as follows:
var TEMP2 10 1 4096    // This defines a per-player (1), read-only (4096) variable with initial value 10.
The following pages contain information on basic gamevar operations as well as conditional statements:
*[[gamevar operators]]
*[[ifvar conditions]]
*[[ifvar conditions]]
*[[gamevar operators]]


<font color="gray">
== Gamevar Flags ==
 
The following table shows all currently defined gamevar flags. The first 3 are the only ones needed under normal circumstances, but one can also assign higher flags to user-defined gamevars (given that you know what you are doing).
 
<font color="grey">
{| {{prettytable}}
{| {{prettytable}}
!<font color="black">Name</font>!!<font color="black">Number</font>!!<font color="black">Description</font>!!<font color="black">Page where such variables should be listed</font>
!<font color="black">Name</font>!!<font color="black">Number</font>!!<font color="black">Hex</font>!!<font color="black">Description</font>!!<font color="black">Page where such variables should be listed</font>
|-
|<font color="black">GAMEVAR_GLOBAL</font>||<font color="black">0</font>||0x000000||<font color="black">global variable; this is the default</font>||
|-
|-
|<font color="black">GAMEVAR_FLAG_GLOBAL</font>||<font color="black">0</font>||<font color="black">global variable; this is the default</font>||
|<font color="black">GAMEVAR_PERPLAYER</font>||<font color="black">1</font>||0x000001||<font color="black">per-player variable</font>||
|-
|-
|<font color="black">GAMEVAR_FLAG_PERPLAYER</font>||<font color="black">1</font>||<font color="black">per-player variable</font>||
|<font color="black">GAMEVAR_PERACTOR</font>||<font color="black">2</font>||0x000002||<font color="black">per-actor variable</font>||
|-
|-
|<font color="black">GAMEVAR_FLAG_PERACTOR</font>||<font color="black">2</font>||<font color="black">per-actor variable</font>||
|GAMEVAR_RESET||8||0x000008|| Internal, don't use.||
|-
|-
|GAMEVAR_FLAG_USER_MASK||3||bitmask controlling what flags can be set from con; only flags less than this can||
|GAMEVAR_DEFAULT||256||0x000100||unused, but always cleared for user-defined gamevars||
|-
|-
|GAMEVAR_FLAG_DEFAULT||256||allow override (not used)||
|GAMEVAR_NODEFAULT||1024||0x000400||Don't reset on actor spawn||
|-
|-
|GAMEVAR_FLAG_SECRET||512||don't dump...||
|GAMEVAR_SYSTEM||2048||0x000800||cannot change mode flags...(only default value)||
|-
|-
|GAMEVAR_FLAG_NODEFAULT||1024||don't add to 'default' array.||
|GAMEVAR_READONLY||4096||0x001000||values are read-only (no setvar allowed)||
|-
|-
|GAMEVAR_FLAG_SYSTEM||2048||cannot change mode flags...(only default value)||
|GAMEVAR_INT32PTR||8192||0x002000||plValue is a pointer to an int32_t||[[Constantly updated gamevars]]
|-
|-
|GAMEVAR_FLAG_READONLY||4096||values are read-only (no setvar allowed)||
|GAMEVAR_FLOATPTR||16384||0x004000||plValue is a pointer to a float||[[Constantly updated gamevars]]
|-
|-
|GAMEVAR_FLAG_INTPTR||8192||plValue is a pointer to an int||[[Constantly updated gamevars]]
|GAMEVAR_INT16PTR||32768||0x008000||plValue is a pointer to a short (int16_t)||[[Constantly updated gamevars]]
|-
|-
|GAMEVAR_FLAG_SYNCCHECK||16384||check event sync when translating||
|GAMEVAR_CHARPTR||65536||0x010000||plValue is a pointer to a char||[[Constantly updated gamevars]]
|-
|-
|GAMEVAR_FLAG_SHORTPTR||32768||plValue is a pointer to a short||[[Constantly updated gamevars]]
|GAMEVAR_NORESET||131072||0x020000||var values are not reset when restoring map state||
|-
|-
|GAMEVAR_FLAG_CHARPTR||65536||plValue is a pointer to a char||[[Constantly updated gamevars]]
|GAMEVAR_SPECIAL||262144||0x040000||flag for structure member shortcut vars||
|-
|-
|GAMEVAR_FLAG_NORESET||131072||var values are not reset when restoring map state||
|GAMEVAR_NOMULTI||524288||0x080000||don't attach to multiplayer packets||
|-
|-
|GAMEVAR_FLAG_SPECIAL||262144||flag for structure member shortcut vars||
|GAMEVAR_Q16PTR||1048576||0x100000|| plValues is a pointer to a q16.16 ||
|-
|-
|GAMEVAR_FLAG_NOMULTI||524288||don't attach to multiplayer packets||
|GAMEVAR_SERIALIZE || 2097152 ||0x200000|| write into permasaves ||
|}</font>
|}</font>
All of the commands in this category are commands that alter the value of one or more gamevars in some way, as opposed to commands which alter [[sprite]]s, [[sector]]s or [[wall]]s.


[[Category:All commands]]
[[Category:All commands]]

Revision as of 09:25, 8 February 2020

Definition

gamevar <varname> <value> <flags>

var <varname> <value> <flags>

A gamevar is a variable that can be used to store numerical data which can then be referenced between actors, states and events. var is hereby semantically equivalent to gamevar.

The gamevar's flags define a bitmap that determines how the variable is treated by the game. For instance, a gamevar with flags of 0 is known as a global variable. A global variable exists once in the code, and any time a global variable is set, the new value is seen by all actors and events. A gamevar with flag bit 1 set is a per-player variable, which exists once for each player in the game. A gamevar with flag bit 2 set is a per-actor variable, which exists as many times in the code as there are sprites in the map. This means that each sprite has its own copy of a per-actor variable stored in memory. Note that a gamevar can only be defined as either global, per-player, or per-actor, but not as a combination thereof.

Gamevars are stored as signed 32-bit integers and therefore have a value range of -2.147.483.648 (-231) to 2.147.483.647 (231-1). Going above and below this range causes the value to overflow and underflow respectively.

Note that it is possible to omit the <value> and <flags> parameters entirely to define a global variable with an initial value of 0, with no other flags set. Example:

var TEMP1

It is also possible to chain flags separately at the end of the gamevar definition, instead of compiling them into a single value, as follows:

var TEMP2 10 1 4096    // This defines a per-player (1), read-only (4096) variable with initial value 10.

The following pages contain information on basic gamevar operations as well as conditional statements:

Gamevar Flags

The following table shows all currently defined gamevar flags. The first 3 are the only ones needed under normal circumstances, but one can also assign higher flags to user-defined gamevars (given that you know what you are doing).

Name Number Hex Description Page where such variables should be listed
GAMEVAR_GLOBAL 0 0x000000 global variable; this is the default
GAMEVAR_PERPLAYER 1 0x000001 per-player variable
GAMEVAR_PERACTOR 2 0x000002 per-actor variable
GAMEVAR_RESET 8 0x000008 Internal, don't use.
GAMEVAR_DEFAULT 256 0x000100 unused, but always cleared for user-defined gamevars
GAMEVAR_NODEFAULT 1024 0x000400 Don't reset on actor spawn
GAMEVAR_SYSTEM 2048 0x000800 cannot change mode flags...(only default value)
GAMEVAR_READONLY 4096 0x001000 values are read-only (no setvar allowed)
GAMEVAR_INT32PTR 8192 0x002000 plValue is a pointer to an int32_t Constantly updated gamevars
GAMEVAR_FLOATPTR 16384 0x004000 plValue is a pointer to a float Constantly updated gamevars
GAMEVAR_INT16PTR 32768 0x008000 plValue is a pointer to a short (int16_t) Constantly updated gamevars
GAMEVAR_CHARPTR 65536 0x010000 plValue is a pointer to a char Constantly updated gamevars
GAMEVAR_NORESET 131072 0x020000 var values are not reset when restoring map state
GAMEVAR_SPECIAL 262144 0x040000 flag for structure member shortcut vars
GAMEVAR_NOMULTI 524288 0x080000 don't attach to multiplayer packets
GAMEVAR_Q16PTR 1048576 0x100000 plValues is a pointer to a q16.16
GAMEVAR_SERIALIZE 2097152 0x200000 write into permasaves