Variable Types

From HIVE
Revision as of 07:43, 19 May 2011 by M0rt (talk | contribs) (Created page with "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 ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 (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 (4B, regardless of type). 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 4B data space.

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.)