Expressions
An expression is anything that works out to a value: a number, a variable, a call to a function, or several of these joined by operators, such as x + width / 2. Expressions can go anywhere a value is needed.
Operators
From the tightest-binding to the loosest:
| Operators | Meaning |
|---|---|
- + ~ (before a value) | negative, positive, and bitwise not (every bit flipped) |
^ | to the power of: 2 ^ 10 is 1024.0 |
* / Mod | multiply, divide, remainder |
Shl Shr Sar | shift bits left, right, and right keeping the sign |
+ - | add (or join strings), subtract |
= <> < > <= >= | equal, not equal, less, greater, less or equal, greater or equal |
And Or Xor | both, either, one but not both (and bit by bit on numbers) |
Operators on the same row work from left to right, so 10 - 3 - 2 is 5, and 2 ^ 3 ^ 2 is (2 ^ 3) ^ 2, 64. A minus sign in front binds tighter than ^, so -2 ^ 2 is 4. Use brackets whenever the order isn't obvious: (a + b) * c.
Not gives 1 when what follows is false, and 0 when it is true. At the start of an expression it applies to everything after it, so Not a And b means Not (a And b). Write (Not a) And b when you mean just a; brackets make Not clear wherever it is.
Numbers
When both sides are integers, the answer is an integer; if either side is a float, the answer is a float. So 7 / 2 is 3, with the fraction dropped (towards zero, so -7 / 2 is -3), while 7 / 2.0 is 3.5. ^ always gives a float. Mod gives the remainder, with the sign of the left side: 7 Mod 3 is 1 and -7 Mod 3 is -1. Dividing an integer by 0 stops the program with an error.
Strings
+ joins strings, and if either side is a string, the other is turned into text first: "Lives: " + 3 is "Lives: 3". This works from left to right, so in "Total " + a + b the two numbers are joined as text one after the other; write "Total " + (a + b) to add them first.
Strings can be compared too. = and <> check whether they are exactly the same, capitals included, and < and > put them in order by their character codes, which is alphabetical for words in the same case. Use Lower or Upper on both sides to compare without caring about capitals.
True and false
Comparisons give back 1 for true and 0 for false. If, While, Until and the logical operators treat 0 as false and any other number as true, so If lives Then means "if lives isn't 0". With And, Or and Xor, both sides are always worked out, even when the first side already decides the answer.
