Portals scripting quick reference
Use this page while building. Each function has a longer beginner-friendly guide linked below.
Choose a tool
| Need | Best tool |
|---|---|
| A visible action with no logic | No-code effect |
| A short condition or formula | Function Effect |
| Several JavaScript steps or player lists | JavaScript Function |
| A static HTML/CSS message | displayHtml |
| An interactive web experience | Iframe |
Task states
Use the numeric task reference in expressions and scripts:
| State | Function Effect | JavaScript Function |
|---|---|---|
| Not Active | $TN{Task} == 0.0 | $TN{Task} === 0 |
| Active | $TN{Task} == 1.0 | $TN{Task} === 1 |
| Completed | $TN{Task} == 2.0 | $TN{Task} === 2 |
When setting a task, use its readable state name:
SetTask('TaskName', 'Active', 0.0)
SetTask('TaskName', 'Active', 0);
The final argument is always a delay in seconds.
Read a named value
$N{Coins} >= 10.0
Number($N{Coins}) >= 10
The task or variable setup decides whether the value is private, persistent, or shared.
Function Effect essentials
| Helper | Signature |
|---|---|
| Set task | SetTask('name', 'NotActive' | 'Active' | 'Completed', delaySeconds) |
| Set value | SetVariable('name', value, delaySeconds) |
| Shared numeric update | UpdateMultiplayerNumericVariable('name', value, operation, delaySeconds) |
| Condition | if(condition, whenTrue, whenFalse) |
| Cap | Min(value, cap) |
| Floor | Max(value, floor) |
A Function Effect’s Trigger On Tasks Change setting re-runs a rule when a referenced task or value changes. Activate On Start runs it once while its task is prepared.
JavaScript Function essentials
const unlocked = $TN{FindKey} === 2;
if (unlocked) {
SetTask('OpenDoor', 'Active', 0);
}
const nextScore = Number($N{Score}) + 1;
SetVariable('Score', nextScore, 0);
The third SetVariable argument is a delay; it is not an operation code.
Shared numeric operations
Use only with a numeric variable configured as multiplayer:
UpdateMultiplayerNumericVariable('TeamScore', 1, 1, 0);
| Operation | Meaning |
|---|---|
| 0 | Set |
| 1 | Add |
| 2 | Subtract |
| 3 | Multiply |
| 4 | Divide |
Use Add for shared point events. It is safer than a local read-modify-write when players score at the same time.
Player lists
| Helper | Purpose |
|---|---|
| AssignNumbersInOrder(players, name) | Assign sequential player numbers. |
| SelectRandomPlayers(players, count) | Choose players from a list. |
| SelectPlayers(players, name, value) | Filter players by a parameter. |
| SetPlayersParameters(players, name, value) | Set one parameter on a player list. |
| CountArray(list) | Count list entries. |
Function Effect uses [Players]; JavaScript Function uses {{Players}}. See Function Effect multiplayer functions or JavaScript multiplayer functions for full examples.
UseEffector
Use only a real numeric target item ID and a supported no-code effect:
UseEffector(12345, 'ShowObject', '{}');
UseEffector(12345, 'HideObject', '{}');
UseEffector(12345, 'NotificationPill', '{"nt":"Unlocked","c":"34D399","hideBackground":false}');
UseEffector(12345, 'ChangeText', '{"text":"New objective"}');
Replace 12345 with the target item’s numeric ID. Do not use UseEffector to invoke JavaScript Function. Full guidance: UseEffector.
displayHtml and iframes
displayHtml('<div style="color:white">Objective updated</div>');
displayHtml('');
displayHtml() is for static HTML/CSS and clears with an empty string. For interactive browser content, use an iframe and its JSON message contract rather than trying to place scripts inside the overlay.
Before you publish
- Create names first, then copy them exactly into code.
- Keep shared data and private data in separate, clearly named variables.
- Test each rule in a fresh play session.
- Test multiplayer updates with at least two players.
- Never store keys or secrets in a script or iframe URL.
