Expressions - earok/scorpion-editor-demos GitHub Wiki
Quirks
There are a few quirks with the expressions system for Scorpion Engine. Some of these are an attempt to keep games running as smoothly as possible on 68000 processors, some of these are simply the result of not having the time and effort put in to fix them and may be improved in future.
Please read every section below so that you have a good grasp of how the expression system works.
No operator order support
There is no operator order in Scorpion, so no support for a system like BEDMAS, all expressions are handled left to right. For example:
- BEDMAS: 5 + 5 * 5 = 5 + 25 = 30
- Scorpion: 5 + 5 * 5 = 10 * 5 = 50
Brackets are supported in Scorpion Engine 2025, and they can be used to force a BEDMAS order, but incur a slight performance overhead due to use of the stack.
If you can rearrange your expression without using brackets, that's recommended. For example:
- 5 * 5 + 5 = 30
- 5 + (5 * 5) = 30
While those equations both give the same result, the first one is faster.
Operator types
| Operator | Description | Example |
|---|---|---|
| + | Plus | 5 + 5 equals 10 |
| - | Minus | 10 - 5 equals 5 |
| * | Multiply | 5 * 5 equals 25 |
| / | Divide | 25 / 5 equals 5 |
| % | Modulus | 26 % 5 equals 1 |
| & | Bitwise and | 3 & 1 equals 1 |
| | | Bitwise or | 3 | 1 equals 3 |
| ^ | Bitwise xor | 3 ^ 1 equals 2 |
| >> | Arithmetic Bitwise shift right | 256 >> 4 equals 16 |
| << | Arithmetic Bitwise shift left | 16 << 4 equals 256 |
Data types
| Data Type | Memory Size | Min Value | Max Value | Performance | Example Use Case |
|---|---|---|---|---|---|
| Byte | 1 Byte | -128 | 127 | Good | Small data values in arrays |
| Word | 2 Bytes | -32,768 | 32,767 | Good | Most kinds of data |
| Long | 4 Bytes | -2,147,483,648 | 2,147,483,64 | Average | High scores and other large data |
| Fraction | 4 Bytes | -32,768.0 | 32,767.0 | Worst | Precision, such as positions for objects that move less than a whole pixel every frame |
Fractions use a fixed number of bits, with 16 for the whole number and 16 for the fractional component. There is no support for a floating number type yet.
All data types are signed
This means in practice that all variables can be set to negative numbers, and will wrap around at the limits.
For example, if you have a byte variable that has a value of 127, and increase it by one, the value is now -128.
Expressions are non fractional by default
In order to reduce CPU overhead on codeblock expressions, as well as to provide a convienient means of rounding down, all expressions are assumed to be for whole numbers unless explicitly configured as such.
Any expression with a period such as MyVar + 2.0 will be considered fractional. An expression that only has variables such as MyVar1. + MyVar2. can be made fractional by adding periods to the end of variable names.
For setting a fractional variable, this means that simply adding a whole number without a fraction will not delete the fractional component.
For example, if you have a variable with a value of 2.5, and you set that with an expression to 0, the value is now 0.5. But if you set it with an expression of 0.0, the value is now 0.
Memory addresses are rounded to even numbers
Due to a quirk with the 68000 processor where a 2 byte value cannot be read from an odd numbered address, all memory addresses of variables are even.
The only practical consideration of this is that the byte data type is largely useless as it won't save any memory over using a word instead, excluding when used in arrays and look up tables where bytes can be allocated contiguously.
Array
Arrays can be defined for any data type.
Arrays are zero indexed. Which means the 1st element is 0, not 1.
This expression increases the 2nd element in an array by 1.
MyArray[1] = MyArray[1] + 1
String
Strings are essentially arrays of bytes, and so codeblock expressions can be used to alter them. This can be handy for things like setting ASCII in individual characters inside of a string.
Just like other arrays, string memory cannot be resized - but a value of 0 is used as a terminator, so placing 0 at a different index could make a string appear longer or shorter.
Look Up Table
Look up Tables are the easiest way to embed raw data in Scorpion Engine. They are simply text files with a number on each line. Accessing lookup tables is identical to accessing arrays.
They are read only, so they do not contribute towards memory usage on Mega Drive and NeoGeo (excluding CD ROM systems), and they don't count towards codeblock variable memory restrictions on Amiga.
Lookup Tables can be keyed to defined constants. For example, if you want to record the minimum score for being able to finish a level, you could do this.
level_target_scores.txt
level01 = 100
level02 = 200
In codeblocks you can now check level_target_scores[level] which would give you that number for the currently loaded level. This will also work for actor tags, animations etc.