Operators Reference
Special Operators
= (equality)
(T?, T) => boolean
Tests for equality, e.g. 5 = 4
yields false
while "s" = "s"
yields true
.
For types tuple
and array
, the comparison is performed element-wise.
Syntax bug! Due to a bug, the type of the second operand must be assignment compatible to the type of the first operand.
I.e., doing5.3 = 5
is valid but5 = 5.3
raises a syntax error. This will be fixed in the future.
!= (inequality)
(T?, T) => boolean
Performs the negated operation of = (equality).
Syntax bug! This operator currently suffers from the same bug as
= (equality)
.
if-then-else (ternary)
(boolean, T?, T) => T
Evaluates the condition (first operand) and if it is true
returns the second operand, otherwise returns the third operand.
Examples
Syntax bug! This operator currently suffers from the same bug as
= (equality)
.
asset
(text) => text
Returns the address of a game asset by using the asset resolver component.
For example, calling asset("star.png")
might return something like "https://game-server.org/game-assets/MySpaceGame/star.png"
.
Check the assets documentation to find out more.
Text Operators
+ (concat text)
(text, text) => text
Performs text (string) concatenation, e.g. "alpha" + "bet"
yields "alphabet"
.
toText (integer)
(int) => text
Converts an integer to text, e.g. toText(5)
yields "5"
.
toText (real)
(real) => text
Converts a real to text, e.g. toText(5.3)
yields "5.3"
.
toText (boolean)
(boolean) => text
Converts a boolean to text, e.g. toText(false)
yields "false"
.
Sequence Operators
exists
(seq[?]) => boolean
first
(seq[E?]) => E
Returns the first element of the sequence or nothing
if the sequence is empty.
second
(seq[E?]) => E
Returns the second element of the sequence or nothing
if the sequence has fewer than two elements.
third
(seq[E?]) => E
Returns the third element of the sequence or nothing
if the sequence has fewer than three elements.
in
(E, seq[E?]) => boolean
Returns true iff the element is contained in the sequence.
The elements are compared using the equality operator.
Examples
collect
(seq[E?]) => array[E]
Collects the elements of the sequence into an array.
This is particularly useful for either stabilizing the results of a query or optimizing the performance of lazy operations.
Examples
+ (concat sequence)
(seq[E?], seq[E]) => seq[E]
>> (append)
(seq[E?], E) => seq[E]
<< (prepend)
(E, seq[E?]) => seq[E]
.. | range
(int, int) => seq[int]
Returns an integer range from the first operand to the second operand (inclusive).
This operator has two alternative equivalent syntaxes:
- The
..
, eg,1..3
- The function
range
, eg,range(1, 3)
Examples
cross
(seq[X?], seq[Y?]) => seq[(X, Y)]
map
(seq[S?], (S) => T?) => seq[T]
Applies the function to the elements of the input sequence and produces the output sequence.
Examples
find
(seq[E?], (E) => boolean) => E
Returns the first element for which the function returns true
or nothing
if there is no such element.
Examples
reduce
(seq[E?], Acc, (Acc?, E) => Acc) => Acc
Logical Operators
Arithmetic Operators
// (integer division)
(int, int) => int
Performs integer division on two integers.
/ (real)
(real, real) => real
Divides two reals.
Note: If this operator is used on integers, they will be converted to real. E.g.
5 / 2
will yield2.5
.
mathFloor
(real) => int
Returns the floor of a real, e.g. mathFloor(2.5)
yields 2
.
mathCeil
(real) => int
Returns the ceil of a real, e.g. mathFloor(2.5)
yields 3
.
mathSgn (integer)
(int) => int
Returns the sign of an int number, that is:
- if number < 0: return -1
- if number = 0: return 0
- if number > 0: return 1
mathSgn (real)
(real) => int
Returns the sign of a real number, that is:
- if number < 0: return -1
- if number = 0: return 0
- if number > 0: return 1