Code & Custom UI
back to documentation

Code & Custom UI

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

Multiplayer Functions

These helpers are for a space where a rule needs to consider more than the current visitor. Use them deliberately: player assignment and shared score updates can affect everyone in the room.

Two kinds of shared data

  • Per-player parameters store a separate value for each player, such as Team, Role, or Slot.
  • Multiplayer numeric variables store one shared number, such as TeamScore.

They are not interchangeable. Create the intended type in your task or variable setup before writing an expression.

Player lists

[Players] represents the players currently in the room.

Function Purpose
AssignNumbersInOrder(players, 'name') Give each player a sequential number.
SelectRandomPlayers(players, count) Pick a subset of players.
SelectPlayers(players, 'name', value) Keep only players whose parameter matches.
SelectPlayersParameters(players, 'name') Read a parameter from each player in the list.
SetPlayersParameters(players, 'name', value) Set a parameter for every player in the list.
SelectPlayerParameter('name') Read the current player’s parameter.
CountArray(list) Count entries in a list.

Assign player slots

AssignNumbersInOrder([Players], 'Slot')

This gives players sequential Slot values beginning at one. Use a separate, explicit task to react to each player’s own Slot value.

Do not put this in a Function Effect that continually re-runs as players or values change unless reassignment is the intended rule.

Give a selected player a role

SetPlayersParameters(
  SelectRandomPlayers([Players], 1.0),
  'Role',
  'Seeker'
)

This selects one current player and sets that player’s Role parameter. Run this from a deliberate round-start action, then test it with the number of players your game supports.

Select a team

SelectPlayers([Players], 'Team', 'Blue')

You can use the result to apply a per-player parameter to every selected player:

SetPlayersParameters(
  SelectPlayers([Players], 'Team', 'Blue'),
  'Ready',
  true
)

Count a condition

CountArray(SelectPlayers([Players], 'Ready', true))

This returns the number of players whose Ready parameter is true. Use it in an if() only after testing the parameter value type you set—text and booleans are different values.

Shared score: use the multiplayer numeric helper

Create TeamScore as a multiplayer numeric variable, then increment it like this:

UpdateMultiplayerNumericVariable('TeamScore', 1.0, 1.0, 0.0)
Operation Result
0.0 Set
1.0 Add
2.0 Subtract
3.0 Multiply
4.0 Divide

Use the Add operation for a shared point event. Do not replace it with a local read-modify-write expression such as SetVariable('TeamScore', $N{TeamScore} + 1.0, 0.0), because simultaneous players can overwrite one another’s result.

Shared score and timer leaderboard recipe

  1. Create a multiplayer numeric TeamScore and use the Add operation above for each scored event.
  2. Start and stop the named timer with the no-code Start Timer and Stop Timer effects at the beginning and end of the round.
  3. Use the no-code leaderboard effects with a matching score label to present or post the final result.
  4. Test with at least two players: score at the same time, join late, and finish the timer while a score is being updated.

The Function Effect manages the compact numeric rule; the visible timer and leaderboard behavior stay in the dedicated no-code effects where creators can inspect them.

Safety checklist

  • Use distinct names for a per-player parameter and a shared variable.
  • Initialize roles and slots from one intentional round-start path.
  • Avoid repeated random selection from effects that re-run on state changes.
  • Test shared scoring with multiple players before publishing.