Difference between revisions of "Variable Types"

From HIVE
Jump to navigation Jump to search
Line 1: Line 1:
A variable is basically a space in memory, that game script (triggers) use for storing data.
+
Each [[variable]] has a type, which indicates what type of data is beeing stored inside it.
  
Each variable has a type, which indicates what type of data is beeing stored inside it (e.g. a number, text or color), and can be defined as up to 4-dimensional [[array]].
 
 
==Variable types==
 
 
There are two categories of variable types: primitive and complex. Primitive are simple data types, such as numbers, that contain small amount of data (1-4 B). Complex types take up much more space (for example point: it has 3 coordinates and facing angle, which are 4 numbers).
 
There are two categories of variable types: primitive and complex. Primitive are simple data types, such as numbers, that contain small amount of data (1-4 B). Complex types take up much more space (for example point: it has 3 coordinates and facing angle, which are 4 numbers).
===Primitive===
+
==Primitive==
 
Primitive variables are created and deleted as you use them dynamically (e.g. when a function/trigger with local variables is executed, all variables are created and given initial values), and their value is stored directly in their memory space.
 
Primitive variables are created and deleted as you use them dynamically (e.g. when a function/trigger with local variables is executed, all variables are created and given initial values), and their value is stored directly in their memory space.
===Complex===
+
List of primitive variable types:
 +
*'''int''' (Integer) - an integer number, max. value +- 2 billion
 +
*'''fixed''' (real) - a real number with fixed point. Max. value +-500k, maximum precision 1/4096
 +
*'''byte''' (byte) - unsigned integer of 1KB size - values 0-255
 +
*'''color''' (color) - collection of 3 colors (RGB) and alpha value
 +
 
 +
==Complex==
 
Complex variables also require 4B of space, but this space is filled only with a pointer (a reference) to another space in memory, which contains the actual data. This means that every time you set a '''new value''' for this variable, a '''new memory''' is taken up and the pointer is pointed there. The old data space is then deleted automatically. This however creates unnecessary load for CPU, which can be avoided by intelligent design. (e.g. if you are updating a dialog for a player, do not call (Player group contining (Player X)) in each line, but just once at the beginning and save it in a variable. For each use a new player group is created in memory, and a milisecond later deleted.)
 
Complex variables also require 4B of space, but this space is filled only with a pointer (a reference) to another space in memory, which contains the actual data. This means that every time you set a '''new value''' for this variable, a '''new memory''' is taken up and the pointer is pointed there. The old data space is then deleted automatically. This however creates unnecessary load for CPU, which can be avoided by intelligent design. (e.g. if you are updating a dialog for a player, do not call (Player group contining (Player X)) in each line, but just once at the beginning and save it in a variable. For each use a new player group is created in memory, and a milisecond later deleted.)
  
 +
Another problem with complex types is the way operator == (comparsion) works. If you, for example, compare two timers, == will return true if both values are link to the ''''same timer''', not if the timers have same timer. There are few exceptions (abilcmd, point, string, unitfilter, unitref).
  
 
List of complex variable types (first are script names, second trigger names):
 
List of complex variable types (first are script names, second trigger names):
Line 31: Line 35:
 
*'''wavetarget'''
 
*'''wavetarget'''
  
Some variable types are present only in trigger editor, in script they are represented by a variable of other type
+
==Fake==
 +
Some variable types are present only in trigger editor (in GUI), in script they are represented by a variable of other, usually primitive, type.
 
List of trigger-only variable types:
 
List of trigger-only variable types:
 
*'''-Preset''' - individually set for each preset, but mostly int
 
*'''-Preset''' - individually set for each preset, but mostly int

Revision as of 16:28, 22 May 2011

Each variable has a type, which indicates what type of data is beeing stored inside it.

There are two categories of variable types: primitive and complex. Primitive are simple data types, such as numbers, that contain small amount of data (1-4 B). Complex types take up much more space (for example point: it has 3 coordinates and facing angle, which are 4 numbers).

Primitive

Primitive variables are created and deleted as you use them dynamically (e.g. when a function/trigger with local variables is executed, all variables are created and given initial values), and their value is stored directly in their memory space. List of primitive variable types:

  • int (Integer) - an integer number, max. value +- 2 billion
  • fixed (real) - a real number with fixed point. Max. value +-500k, maximum precision 1/4096
  • byte (byte) - unsigned integer of 1KB size - values 0-255
  • color (color) - collection of 3 colors (RGB) and alpha value

Complex

Complex variables also require 4B of space, but this space is filled only with a pointer (a reference) to another space in memory, which contains the actual data. This means that every time you set a new value for this variable, a new memory is taken up and the pointer is pointed there. The old data space is then deleted automatically. This however creates unnecessary load for CPU, which can be avoided by intelligent design. (e.g. if you are updating a dialog for a player, do not call (Player group contining (Player X)) in each line, but just once at the beginning and save it in a variable. For each use a new player group is created in memory, and a milisecond later deleted.)

Another problem with complex types is the way operator == (comparsion) works. If you, for example, compare two timers, == will return true if both values are link to the 'same timer, not if the timers have same timer. There are few exceptions (abilcmd, point, string, unitfilter, unitref).

List of complex variable types (first are script names, second trigger names):

  • abilcmd (Ability command)
  • bank (Bank)
  • camerainfo (Camera)
  • marker
  • order (Order)
  • playergroup (Player Group)
  • point (Point)
  • region (Region)
  • soundlink (Sound link)
  • string (String)
  • text (Text)
  • timer (Timer)
  • transmissionsource (Transmission source)
  • unitfilter (Unit filter)
  • unitgroup (Unit group)
  • unitref
  • waveinfo
  • wavetarget

Fake

Some variable types are present only in trigger editor (in GUI), in script they are represented by a variable of other, usually primitive, type. List of trigger-only variable types:

  • -Preset - individually set for each preset, but mostly int
  • -Game link - always string
  • -File - always string
  • Actor Message - string
  • Animation Name - string
  • Attribute ID(both) - string
  • Attribute value - string
  • Cinematic - int
  • Conversation - int
  • Conversation reply - int
  • Conversation state - string
  • Dialog - int
  • Dialog item - int
  • Difficulty - int
  • Leaderboad - int
  • Mercenary - int
  • Mission archive - int
  • Model Camera - string
  • Objective - int
  • Ping - int
  • Planet - int
  • Player Color - int
  • Purchase item - int
  • Research (all three) - int
  • Unit type - string
  • Water - string