Skip to content

DSL: operators

Timothé ROSAZ edited this page Mar 4, 2025 · 2 revisions

Here's a list of the various operator existing in the USS syntax.

'Math'-like operators

Nothing game-changing here :

  • +, -, /, ^ : will do math operations on numbers. Will "return" a number.
  • If left and right operands are durations, returns a duration (but / and * need the same duration's type).

Examples

define %a = 7.5 + 4.5; # a = 12
define %b = %a - 10;   # b = 2
define %c = %a / %b;   # c = 6

Durations

You can add and subtract durations, and obtain a new one. You can also divide a duration by another, and obtain a number.

Examples:

define %dur_a = 5 minutes;
define %dur_b = %dur_a * 2; # 10 minutes
define %dur_c = %dur_a + %dur_b; # 15 minutes
define %count = %dur_c / %dur_a; # 3

Concatenation

The + operator can also "add" other types, such as :

  • string + string => Concatenation of both strings.
  • string + any => Concatenation of the string and the other elements (using the Object#toString() java method).

Position delta

You can add a Vector to a location, using a + and - operator.

Example:

define %pos_caster = position of %caster;
define %block_under_caster = %pos_caster - [[0, -1, 0]];

List operators

Four list operators exist in USS.

  • :+ : append an element to a list.
  • :- : remove an element from a list.
  • :/ : remove an element in a list, using its index.
  • :? : test if an element is contained in a list.

Example :

# Create a list
%list = [["a", "b", "c"]];

# Append a new value
%list :+ "d"; # => List : {a, b, c, d}

# Remove the index 1
%list :/ 1; # => List : {a, c, d}

# Remove the value "a"
%list :- "a"; # => List : {c, d}

# Test if list contains "c";
%list :? "c"; # List will not change, but expression returns true.

Comparators

Each of them accept numbers OR durations and return a boolean.

  • >=, >, <=, <

Each of the following can test equality on any type :

  • ==, !=

Null

You can compare a null value and a variable (or a result) using the == and != operators.

Clone this wiki locally