Operators Reference
Special Operators
= (equality)
(T?, T) => booleanTests 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 = 5is valid but5 = 5.3raises a syntax error. This will be fixed in the future.
!= (inequality)
(T?, T) => booleanPerforms the negated operation of = (equality).
Syntax bug! This operator currently suffers from the same bug as
= (equality).
if-then-else (ternary)
(boolean, T?, T) => TEvaluates 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) => textReturns 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) => textPerforms text (string) concatenation, e.g. "alpha" + "bet" yields "alphabet".
toText (integer)
(int) => textConverts an integer to text, e.g. toText(5) yields "5".
toText (real)
(real) => textConverts a real to text, e.g. toText(5.3) yields "5.3".
toText (boolean)
(boolean) => textConverts a boolean to text, e.g. toText(false) yields "false".
Sequence Operators
exists
(seq[?]) => booleanfirst
(seq[E?]) => EReturns the first element of the sequence or nothing if the sequence is empty.
second
(seq[E?]) => EReturns the second element of the sequence or nothing if the sequence has fewer than two elements.
third
(seq[E?]) => EReturns the third element of the sequence or nothing if the sequence has fewer than three elements.
in
(E, seq[E?]) => booleanReturns 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) => EReturns 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) => AccLogical Operators
Arithmetic Operators
// (integer division)
(int, int) => intPerforms integer division on two integers.
/ (real)
(real, real) => realDivides two reals.
Note: If this operator is used on integers, they will be converted to real. E.g.
5 / 2will yield2.5.
mathFloor
(real) => intReturns the floor of a real, e.g. mathFloor(2.5) yields 2.
mathCeil
(real) => intReturns the ceil of a real, e.g. mathFloor(2.5) yields 3.
mathSgn (integer)
(int) => intReturns 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) => intReturns the sign of a real number, that is:
- if number < 0: return -1
- if number = 0: return 0
- if number > 0: return 1