Code & Custom UI
back to documentation

Code & Custom UI

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

Function Effect

Function Effect is the right tool when a visual task needs one small rule: check progress, compare a value, then set a task or variable. It uses an expression language rather than JavaScript, so it is a good first step before writing code.

Use it for things such as a locked door, a quest gate, a score cap, or a short cooldown.

Choose the right tool

Need Use
Start an animation, show an object, play sound, or change a setting The matching no-code effect
Check a few tasks or values and make a simple decision Function Effect
Keep several steps of logic together, work with arrays, or call an effect from code JavaScript Function
Build a real interactive web page or mini-game An iframe

How a Function Effect runs

Add the effect to a task in Interactive Studio, write one expression, then use Test Action before relying on it in play mode.

The effect can run in three ways:

  1. Its containing task or trigger fires.
  2. Activate On Start is enabled, which runs it once when that task is prepared.
  3. Trigger On Tasks Change is enabled, which re-runs it when a task or value named in the expression changes.

Use the third option only for rules that should continuously react to state. Do not make an expression repeatedly change the same value it watches unless the condition prevents a loop.

Task states: use numbers in expressions

Every task has three states. In Function Effect expressions, use $TN{Task name} to read the state as a number:

State $TN value
Not Active 0.0
Active 1.0
Completed 2.0

For example, this checks whether FindKey is complete:

$TN{FindKey} == 2.0

When you set a task, use the readable state name:

SetTask('OpenDoor', 'Active', 0.0)

The last number is a delay in seconds. 0.0 means immediately.

First recipe: unlock a door

Set up two tasks first:

  1. FindKey becomes Completed when the player finds the key.
  2. OpenDoor has the visual effects that reveal or open the door when it becomes Active.

On the rule that should check the key, add this Function Effect:

if(
  $TN{FindKey} == 2.0,
  SetTask('OpenDoor', 'Active', 0.0),
  ''
)

The empty string in the last branch means “make no change.” It is deliberately a string because SetTask() returns a text result. Keeping both branches the same kind of result avoids expression type errors.

Scope comes from the things you create

A Function Effect does not decide whether progress is private or shared. The task and variable configuration does.

  • Use a single-player task or variable for each visitor’s own progress.
  • Use a multiplayer task or multiplayer numeric variable for one shared state in the space.
  • Give single-player and multiplayer data different names. Reusing a name makes a rule hard to reason about and debug.

Build safely

  • Create and name the task or variable before referencing it.
  • Copy names exactly; capitalization and spaces matter.
  • Use decimal values in Function Effect examples: 1.0, 0.0, and 2.5.
  • Keep one expression responsible for one decision. Chain visible effects through tasks instead of cramming unrelated actions into one formula.
  • Test in a fresh play session after changing scope, persistence, or a task name.

Next: learn the expression basics, then use the Portals-specific functions to read and change game state.