Skip to content

Operators

Operators are special characters (or a sequence of them) that represent special meaning in the code. In FLEx we can categorize them into few groups.

Comparison operators

For use inside of conditions.

  • > greater operator - @courage > 5
  • < lesser operator - @courage < 5
  • >= greater-or-equal operator - @courage >= 5
  • <= lesser-or-equal operator - @courage <= 5
  • == equality operator - @courage == 5

Equality operator can be used with any variable type, other operators work only with integer and float values.

[#if (@alignment == "chaotic neutral")] _"I am not surprised it was **you** who caused it."_ [/if]

Interpolation operators

They are used inside of interpolation contents.

General logic is as follows: <value or variable> <operator> <value or variable> => <value>.

  • + addition operator - @perception + 5
  • - subtraction operator - @perception - 5
  • * multiplication operator - @perception * 5
  • / division operator - @perception / 5

Addition operator can be used with any value types. If at least one part is not a number then everything is coerced to a string value.

Other operators can only be used with integer and float values.

::: @gold is 75 You buy a healing potion. You now have {{ @gold - 20 }} gold coins left.
::: @first_clue is "The treasure lies", @second_clue is "beneath the weeping willow." You piece together the clues: {{ @first_clue + " " + @second_clue }}

Effect operators

Effect operators are used inside of effect blocks. They mutate the values of variables upon selection of a passage by a player.

  • = assignment operator - @evil = true
  • += addition assignment operator - @luck += 1
  • -= subtraction assignment operator - @luck -= 1
  • *= multiplication assignment operator - @luck *= 0.5
  • /= division assignment operator - @luck /= 0.5

Assignment operator replaces old value of the variable with a new one (types must match!).

Other operators mutate the existing value in-place and can only be used with numbers.

[#passage] Go left [/passage] [#effect] @courage += 1 [/effect]

Logical operators

They’re used to chain multiple conditions together.

  • && logical and operator - @brave == true && @sanity > 5
  • || logical or operator - @brave == true || @sanity > 5
::: @brave is true, @sanity is 7 [#if (@brave == true || @sanity > 5)] You enter the room with confidence. [/if]

See also