Data Types
Every piece of data is expressed as one of the existing data types. You can think of data types as a classification of the data. For example, you do know that 1.254 is a number, while "Hello World" is a string of characters.
SQF knows several data type, some more frequently used, some less so.
The most commonly used data types are:
Numbers
Number are exactly what you would think they are. 1 is a number. 3.1415 is a number. -1000 is a number. Very large or small numbers can be written as powers of ten by using 'E' or 'e': 1e3 is 1 times ten to the third power (1000), while 2e-3 is 2 times 10 to the power of -3 (0.002). Note that SQF does not make any distinction between whole numbers and floating point numbers.
Strings
Strings are squences of characters, enclosed in either double (") or single (') quotes. "This is a string" is an example of a double-quoted string. 'This is a single-quoted string' is another example of a (this time single-quoted) string. Note that a double quote must be closed by another double quote and vice versa. So, "This is not a string' is not correct.
Strings are used as names and for other purposes.
Booleans
A boolean is a truth value. It can either be true, or false. Their use is mainly for conditions (see later chapter), but just like numbers ans strings can be used in other expressions. We'll be talking about this in detail later.
Objects
Objects are "handles" for anything in game. The player is an object. Any vehicle is an object. Enemy AI are objects. Basically, everything that manifests itself in the game world is an object, even triggers and modules (Exception of this rule: Markers are not objects).
A special object is defined as well, the "null object", which represents nothin. In SQF, it's expressed as objNull.
Code
Code is anything you can execute. In SQF, code has it's own data type. It is written as a sequence of statements enclosed in curly braces. Examples for code data types:
Arrays
Finally, we have arrays. An array is a special datatype in that it's a collection of multiple items of data of varying types. Arrays are written as comma separated lists of items, enclosed in square brackets [].
The order in which items are listed is significant. The first item is always item number 0, the second one is 1, and the last one is the n-1st item (if there are n item in an array).
For beginners, this is probably the most difficult data type to understand, so let's see a few examples:
Arrays can be manipulated in a number of ways. We'll look at them in an extra chapter.
As mentioned above, some data types are rarely used. For example, tasks, briefings and groups are data types in their own right, comparable to objects. For groups, there's even the same null group, "grpNull"
To summarize:
Every piece of data is expressed as one of the existing data types. You can think of data types as a classification of the data. For example, you do know that 1.254 is a number, while "Hello World" is a string of characters.
SQF knows several data type, some more frequently used, some less so.
The most commonly used data types are:
- Number
- String
- Boolean
- Object
- Code
- Arrays
Numbers
Number are exactly what you would think they are. 1 is a number. 3.1415 is a number. -1000 is a number. Very large or small numbers can be written as powers of ten by using 'E' or 'e': 1e3 is 1 times ten to the third power (1000), while 2e-3 is 2 times 10 to the power of -3 (0.002). Note that SQF does not make any distinction between whole numbers and floating point numbers.
Strings
Strings are squences of characters, enclosed in either double (") or single (') quotes. "This is a string" is an example of a double-quoted string. 'This is a single-quoted string' is another example of a (this time single-quoted) string. Note that a double quote must be closed by another double quote and vice versa. So, "This is not a string' is not correct.
Strings are used as names and for other purposes.
Booleans
A boolean is a truth value. It can either be true, or false. Their use is mainly for conditions (see later chapter), but just like numbers ans strings can be used in other expressions. We'll be talking about this in detail later.
Objects
Objects are "handles" for anything in game. The player is an object. Any vehicle is an object. Enemy AI are objects. Basically, everything that manifests itself in the game world is an object, even triggers and modules (Exception of this rule: Markers are not objects).
A special object is defined as well, the "null object", which represents nothin. In SQF, it's expressed as objNull.
Code
Code is anything you can execute. In SQF, code has it's own data type. It is written as a sequence of statements enclosed in curly braces. Examples for code data types:
- {hint "XXX";}
- {_a = 0;}
Arrays
Finally, we have arrays. An array is a special datatype in that it's a collection of multiple items of data of varying types. Arrays are written as comma separated lists of items, enclosed in square brackets [].
The order in which items are listed is significant. The first item is always item number 0, the second one is 1, and the last one is the n-1st item (if there are n item in an array).
For beginners, this is probably the most difficult data type to understand, so let's see a few examples:
- [1, 2, 3] - This is an array consisting of three elements, the numbers 1, 2 and 3
- ["task", player, 4.5, ["A", "B"]] - This is an array consisting of four elements, the first one being a string ("task"), the second an object (player), the third a number (4.5) and the last one an array consisting of two strings, "A" and "B".
- [] - This is also an array, consisting of no elements at all (an empty array)
Arrays can be manipulated in a number of ways. We'll look at them in an extra chapter.
As mentioned above, some data types are rarely used. For example, tasks, briefings and groups are data types in their own right, comparable to objects. For groups, there's even the same null group, "grpNull"
To summarize:
- A data type represents an item of a specific kind
- Numbers represent real numbers
- Strings are sequences of characters
- Booleans are truth values
- Code can be executed
- Arrays are collection of multiple data items of different kind