Skip to content

Session Expressions

JaThePlayer edited this page Dec 21, 2025 · 2 revisions

Many entities in Frost Helper which accept flags as conditions can instead use Session Expressions. (Check tooltips to see if they are).

Instead of simply checking a single flag, Session Expressions can check multiple flags and even session counters, and perform arithmetic and logic operations on them.

A condition using these Expressions is considered to be met if the value of the Expression is not 0.

Basic Syntax

  • flagName - Providing a flag name on its own checks if that flag is set, returning 1 if it is, 0 otherwise.
  • !flagName - Inverts the logic for checking flags, returning 0 if the flag is set, 1 otherwise.
  • #counterName - Reads the value of a Session Counter (integer) instead of a flag.
  • @sliderName - Reads a Session Slider (floating-point number).
  • $cmdName - Uses a Simple Command. List of commands.
  • $funcName(arg1, arg2, ..) - Calls a function with the provided arguments. List of functions.

Logic

&& and || operators can be used to compare 1/0 values, mostly useful for flags:

  • For example: (flagA && flagB) || flagC is met if either both flagA and B are set, or flagC. (or all of them at once)
  • For example: #money >= #cost && canBuyUpgrades

Arithmetic

When working with Session Counters, it can be useful to perform arithmetic on them.

You can use basic arithmetic operators: + - * / % // and comparison operators <, <=, >, >=, ==, !=

  • For example: #counterA + #counterB < 10 checks if the sum of counters counterA and counterB is less than 10.

Because flags get converted to 0 and 1, you can perform arithmetic on flags as well.

  • For example: flagA + flagB + flagC == 2 checks if exactly 2 of the 3 provided flags are true.

NOTE: The / operator will perform integer division when supplied with integers on both the left and right side. That is, 5 / 2 == 2. If you wish to force division on floating-point numbers instead, you can use the // operator, in which case 5 // 2 == 2.5

Strings

String literals can be created with "contents of your string".

String interpolation can be done by using $(...), for example: "Counter 'count' is: $(@count)".

The most common usecase of strings is the Counter Display Trigger. For example, to create a visible distance traveled counter, the Counter field can be set to "$($truncate($player.x / 8)) tiles" (Notice the " characters surrounding the expression, needed to create a string in the first place):

Click to get a copy-able Counter Display trigger.
{
    {
        _fromLayer = "triggers",
        _id = 9935,
        _name = "FrostHelper/CounterDisplay",
        _type = "trigger",
        counter = "\"$($truncate($player.x / 8)) tiles\"",
        height = 56,
        icon = "",
        iconColor = "ffffff",
        removeFlag = "",
        showOnRoomLoad = false,
        textColor = "ffffff",
        visibleFlag = "",
        width = 8,
        x = 1496,
        y = 656
    }
}

Indirect Access

Interpolated strings can also be used to indirectly access flags, counters or sliders.

  • f"flag_$(#x)" - If counter #x is 0, checks flag flag_0, #x == 1 checks flag_1 etc.
  • #"counter_$(#x)"
  • @"slider_$(#x)"

Example Usage

Session Counter Trigger

Session Counter Triggers support Session Expressions in the Value field (as do many other session counter related triggers) However, there are 2 major differences when using Expressions in them:

  • For backwards compatibility, providing a name on its own treats that name as a Session Counter, not a flag! (That is, setting Value to name will read the session counter called name, not a flag! However, name + 2 will read a flag called name!)
  • Expressions are treated as returning a number, not a boolean value.

For example, if you want to set a Counter points to the sum of the deaths in the current room plus the value of a Counter bonus: image

Interactions with other mods

While other mods might not support this feature, you can still make use of it to control other flag-based entities.

Say you want to change rainbow spinner colors when #money>=5 && otherFlag using a Flag Rainbow Spinner Color Controller.

You can use a Flag If Expression controller entity, which sets a flag if a Session Expression is met, and unsets it immediately when it isn't. image

API

Frost Helper provides a MonoMod Export api for creating and evaluating Session Expressions: Link

Clone this wiki locally