Jump to content

Category:Gamevar manipulation

From EDukeWiki
(Redirected from Gamevar)

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.

Keep in mind that global variables are still global, even when defined within a state block. The variable definition is effectively "hoisted," so the variable will not be reset to the initial value each time its definition is encountered.

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

Flags

The following table shows all currently defined gamevar flags. The first 2 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).

ExposedValueHexLabelDescription
Yes10x00000001GAMEVAR_PERPLAYERPer-player variable.
Yes20x00000002GAMEVAR_PERACTORPer-actor variable.
30x00000003GAMEVAR_USER_MASKBitmask controlling what flags can be set from con; only flags less than this can.
Internal80x00000008GAMEVAR_RESET
2560x00000100GAMEVAR_DEFAULTAllow override (not used, but always cleared for user-defined gamevars).
5120x00000200GAMEVAR_FLAG_SECRETDon't dump... (no longer defined in eduke32 source code as of r10016)
Yes10240x00000400GAMEVAR_NODEFAULTDon't reset on actor spawn. Useful if you want a variable to be set once you start the game (otherwise it's reset each time you start a new game).
20480x00000800GAMEVAR_SYSTEMCannot change mode flags...(only default value)
40960x00001000GAMEVAR_READONLYValues are read-only (no setvar allowed)
81920x00002000GAMEVAR_INT32PTRplValues is a pointer to an int32_t
163840x00004000GAMEVAR_FLAG_SYNCCHECKcheck event sync when translating (no longer defined in eduke32 source code as of r10016)
327680x00008000GAMEVAR_INT16PTRplValues is a pointer to a short
Yes1310720x00020000GAMEVAR_NORESETVariable values are not reset when restoring map state
2621440x00040000GAMEVAR_SPECIALFlag for structure member shortcut vars
Yes5242880x00080000GAMEVAR_NOMULTIDon't attach to multiplayer packets
10485760x00100000GAMEVAR_Q16PTRplValues is a pointer to a q16.16
Yes20971520x00200000GAMEVAR_SERIALIZEWrite into permasaves