Variables¶
1. Data types¶
Throughout the execution of a script, a lot of data is being manipulated all the time. This data can be of different types, each serving a different purpose. The following table lists the data types available in XS and their corresponding keywords.
Data type | Keyword | Possible values | Example |
---|---|---|---|
Boolean | bool |
true or false |
true |
Integer | int |
Any whole number between -999999999 and 999999999 |
42 |
Float | float |
Any real number between -999999999.999999 and 999999999.999999 |
3.141592 |
String | string |
Any sequence of characters enclosed in double quotes "..." . See Strings. |
"Hey there, partner." |
Vector | vector |
See Vectors. | xsVectorSet(0, 0, 0) |
2. Variables¶
Variables are used to store data to be retrieved and manipulated later.
2.1. Definition¶
Defining a variable means creating a new variable by giving it a name, a type and a value. Variables must be defined before they can be used.
Syntax of variable definition
2.1.1. Type¶
This can be any of the data types listed above. This
determines what kind of data the variable can store, e.g. a variable of type
int
cannot store a string.
2.1.2. Name¶
There are a few rules to follow when naming variables:
- Names are case-sensitive, e.g.
foo
andFoo
are two different names. - Names can only contain letters, numbers and underscores. Diacritics are not allowed.
- Names must start with a letter or an underscore.
- Names cannot be the same as a keyword.
- Variables cannot have the same name as a function, rule or rule group.
- Variables cannot have the same name as another variable, constant or label in the same scope.
2.1.3. Value¶
This is the data that the variable will store. The value must be of the same type as the variable.
2.1.4. Examples¶
Some examples of variable definitions
2.2. Assignment¶
Assigning a variable means changing the value of an existing variable. The variable must have been defined before it can be assigned.
Syntax of variable assignment
2.2.1. Examples¶
Some examples of variable assignments
2.3. Constants¶
Constants are variables whose value cannot be changed after they have been
defined. They are defined in the same way as variables, except that the
const
keyword is written before the type.
Syntax of constant definition