Code & Custom UI
back to documentation

Code & Custom UI

Use Function Effects, JavaScript, and custom interfaces when no-code tools are not enough.

Expressions: the basics

A Function Effect is one expression. It can read task state and values, do math, make a comparison, or call a Portals helper such as SetTask().

Start with a tiny expression, press Test Action, and add one piece at a time.

Numbers

Use numeric values for scores, counters, delays, and calculations. Decimal notation keeps expressions consistent:

0.0
3.5
10.0

Text

Text is wrapped in single quotes. You need it for task names, task state names, and text variables:

'OpenDoor'
'Active'
'Welcome back'

Read a task

Use $TN{Task name} for a numeric task state.

$TN{CollectThreeGems} == 2.0

The values are always:

State Value
Not Active 0.0
Active 1.0
Completed 2.0

This format is easier to combine with numeric comparisons than a state label.

Read a value or timer

Use $N{Value name} to read a named value. The same format can read a timer after you have started that timer with the no-code Start Timer effect.

$N{Coins} >= 10.0
$N{RaceTimer} < 60.0

If a value has never been set, initialize it through a task before using it for important logic. If a timer has not been started, do not expect it to represent elapsed play time.

Compare and combine

Comparisons produce true or false:

$N{Coins} >= 10.0
$TN{FindKey} == 2.0

Use && when both checks must be true and || when either may be true:

($N{Coins} >= 10.0) && ($TN{FindKey} == 2.0)

Parentheses make rules readable

Use parentheses around parts of a rule. They show the intended order and make future edits safer.

($N{Stars} >= 3.0) && ($TN{TalkToGuide} == 2.0)

Store a calculated value

An expression can calculate a result without saving it. Use SetVariable() when the result should become game state:

SetVariable('BonusPoints', $N{Score} + 5.0, 0.0)

This writes Score + 5 into BonusPoints immediately. The third argument is a delay in seconds, not an operation mode.

A complete small rule

This sets CanEnter only when the player has the key and enough stars:

if(
  ($TN{FindKey} == 2.0) && ($N{Stars} >= 3.0),
  SetVariable('CanEnter', 1.0, 0.0),
  SetVariable('CanEnter', 0.0, 0.0)
)

For decisions with several outcomes, continue with conditions. For every available read and write helper, see Portals-specific functions.