With these numbers, which may be either literals (hard-coded in script) or read from a teletext frame, you can perform a variety of actions and also you can use the numbers in decision-making.
There are 26 variables available for use; that is, there are twenty six bits of memory in which you can store numbers. They are called A to Z, each letter of the alphabet is a variable.
The first sixteen (A through P) are integer variables and can store only whole numbers. The remaining ten (Q through Z) are float variables and can store numbers with up to nine decimal places of precision.
set R to 123.45 add(R, 32)
You can specify integer numbers in hex (base 16) by prefixing with an ampersand '&' symbol:
channelid(A) if (A ! &EF01) error("Wrong channel!")
You can specify integer numbers in binary (base 2) by prefixing with a percent '%' symbol:
set M to %11110000 and(A, %1111)
The following examples all set 'A' to 123:
set A to 123 set A to &7B set A to %1111011
For negatives, simply prefix with a minus symbol:
set A to -123 set A to -&7B set A to -%1111011
All variables are zero when the script begins.
You have a number of mathematical possibilities:
|Addition||C = A + B||set C to A|
|For increments, you could use "C++".|
|Subtraction||C = A - B||set C to A|
|For decrements, you could use "C--".|
|Multiplication||C = A × B||mul(C, A, B)|
|Division||C = A ÷ B||div(C, A, B)|
|Modulus||C = A MOD B||mod(C, A, B)|
|And||C = A & B||and(C, A, B)|
|Exclusive Or||C = A % B||eor(C, A, B)||Windows: you could use "xor(C, A, B)".|
|Left shift||C = A << B||lsl(C, A, B)|
|Right shift||C = A >> B||lsr(C, A, B)|
|Not||C = NOT A||not(C, A)|
|Or||C = A | B||or(C, A, B)|
will result in A being set to 12.set R to 12.75 set A to R
The roundcast command rounds to nearest.
will result in A being set to the expected 13.set R to 12.75 roundcast(A, R)
Windows: All calculations are performed to 'double' floating point accuracy, and are then clipped to nine decimal places (with rounding) to try to ensure the same results as the RISC OS version.
RISC OS: All calculations are performed with floating point accuracy.
If you specify floats as the destination variable, the internal result is copied across. If you specify integers as the destination, the internal result is rounded to the nearest whole number.