Many puzzles can be created using only events, effect sequences, and solved conditions. Custom scripting is only required for more advanced logic, typically when the puzzle needs to remember previous player actions or maintain state.
For example, if players must press a series of buttons in the correct order, the script needs to keep track of which buttons have already been pressed and which button is expected next.
To enable scripting, check the Use custom script option in the puzzle settings.
You can write your scripts using standard JavaScript, but keep in mind that some modern syntax features may not be supported. For example, string building should use simple concatenation ("Score: " + value) instead of template literals (`Score: ${value}`). Stick to basic JavaScript constructs like variables, functions, conditionals, and loops to ensure your scripts run reliably.
Enable Use custom script, then open the Script – <puzzle name> tab to edit the code. Designer initializes a script skeleton. See the example below:
function isReady() {
// This function is used by the game logic to verify that the puzzle is properly prepared,
// such as ensuring attributes are removed and the initial state is correctly set.
// Your code here -------------------------
return false; // or true
}
function isSolved() {
// The game logic checks this function to determine for the puzzle to be solved
// Your code here -------------------------
return false; // or true
}
function onReset() {
// Puzzle is reset
// Your code here -------------------------
}
function onActivate() {
// Puzzle is activated,
// Your code here -------------------------
}
function onTimeTick(ms) {
// You can check conditions here at regular intervals using 'ms' as a time reference.
// Note: 'ms' does not reference the game start time.
// This function is called approximately every 50 ms.
// Reminder: The puzzle must be active to receive events here.
// Your code here -------------------------
}
function onEvent(objectId, state, ms) {
// Handle state change events from input objects.
// Note: The puzzle must be active to receive these events.
// For example, if a switch is triggered before the puzzle is active,
// the event will not be received here.
// To address this, also check the initial state of switches
// in the onActivate method using getState().
// Your code here -------------------------
}Let’s take a look at this script. The functions shown here will be called by the system and need to be implemented.
The following two functions are continuously polled by the system in a fast loop to actively monitor their conditions:
isReady– This function is polled while the game is not running, to check whether the puzzle is properly prepared. You should implement any necessary checks here to confirm that the puzzle is ready to start..isSolved– This function is polled continuously while the game is running and the puzzle is active. Returntruewhen the puzzle has reached its solved state.
The following functions will be called as events:
onActivate– Called when this task becomes active, either in the game flow or in a Single Test. During normal gameplay, activation is usually triggered by another task reaching the “completed” state.onReset– Called when the game is reset, or when this task is manually reset.onTimeTick(ms)– Called every 50 milliseconds. Themsparameter is not tied to game time but can be used as a reference to measure elapsed time between events.onEvent(objectId, state, ms)– Called whenever any object in the game changes state. This may include objects unrelated to the current puzzle, so you should check theobjectIdto determine if the event is relevant. Thestateparameter contains the current state of the specified object, andmsshares the same time reference as inonTimeTick.
Important note: You can add log statements to your script for debugging purposes—these will appear in the Logics Console. However, be cautious when logging inside isReady and isSolved, as these functions are called very frequently and can flood the console, potentially affecting performance. If you need to debug them, use a debug flag or limit how often logs are written, and make sure to remove or disable these logs before running the game for real.
The same caution applies to the onTimeTick event—only log meaningful changes or state transitions to avoid excessive output.
Using control functions
The following functions are available in the 3.5.2 script runtime. They control objects and Logic Controls from your script. Use the configured Object ID for id, and the configured component name for Operations, Locks and Switches.
In this reference, t is startTimeSecs: a number in seconds relative to the start of the command sequence queued by the current callback. It is not an absolute game-clock time. For example, schedule a light at 0 and thunder at 0.5 to play the sound half a second after the light. Commands run through the normal object/device mapping, so the target must support the command.
setActive(id, t)
Target: Output.
Sets the output active.setInactive(id, t)
Target: Output.
Sets the output inactive.setValue(id, t, value)
Target: Output.
value: integer supported by the configured output channel.pulse(id, t, duration)
Target: Output.
duration: active duration in seconds.pulseTrain(id, t, highDuration, lowDuration)
Target: Output.
Both durations are seconds; alternates active and inactive periods.setVariable(id, t, value)
Target: Variable.
value: text; use a project Variable, not a System value.setPercentage(id, t, percentage)
Target: Position Control.
percentage: number from 0 to 100.transitionPercentage(id, t, percentage, duration)
Target: Position Control.
percentage: 0–100; duration: seconds.setLight(id, t, rgb, temperature, intensity)
Target: Light.
rgb: integer 0xRRGGBB or null; temperature and intensity: 0–100 or null.transitionLight(id, t, rgb, temperature, intensity, duration)
Target: Light.
Same light parameters; duration: seconds.setLightByte(id, t, rgb, temperature, byteValue)
Target: Light.
rgb/temperature as above; byteValue: whole integer 0–255.transitionLightByte(id, t, rgb, temperature, byteValue, duration)
Target: Light.
Same byte parameters; duration: seconds.playPattern(id, t, file, loop, masterIntensity, speed)
Target: Compatible DMX Light.
file: pattern filename; loop: boolean; masterIntensity: 0–100; speed: 0.50–2.00.playPatternByte(id, t, file, loop, byteValue, speed)
Target: Compatible DMX Light.
Same pattern parameters; master intensity is an integer byte 0–255.playMedia(id, t, file, position, volume, loop)
Target: Audio/Video Player.file: media filename;position: intended start position in seconds, but use 0 with Audio Box because of the current script-wrapper limitation below;volume: 0–100 or null;loop: boolean.stopMedia(id, t, volume, duration)
Target: Audio/Video Player.
volume: fade target 0–100, then stop; duration: seconds. Use null for volume to stop without a volume fade.fadeVolume(id, t, volume, duration)
Target: Audio/Video Player.
volume: 0–100; duration: seconds.setDuckingLevel(id, t, level)
Target: Audio/Video Player.
level: 0–100, controlling the ducking level supported by the player.showImage(id, t, file)
Target: Image Viewer.
file: image filename.showView(id, t)
Target: Custom/Time Viewer.
Shows the configured view.showText(id, t, text)
Target: Text Viewer.
text: string to display.hide(id, t)
Target: Image/Text/Time/Custom Viewer.
Hides the target view.enableInput(id, t, playerChannel, volume)
Target: Audio Input.playerChannel: intended target audio-player channel identifier, not its logical object ID;volume: 0–100 or null. For Audio Box use Enable Input in an Effect Sequence because of the current script-wrapper limitation below.disableInput(id, t)
Target: Audio Input.
Disables the input.launchOperation(name, t, repeatCount, repeatInterval)
Target: Operation.
name: configured Operation name; repeatCount: integer number of additional repeats (0 runs once); repeatInterval: seconds between sequence starts, minimum 1 second when repeating.cancelOperation(name, t)
Target: Operation.
Cancels scheduled commands; already-started media needs its own stop command.lock(name, t)
Target: Lock control.
name: configured Lock name.unlock(name, t)
Target: Lock control.
name: configured Lock name.switchOn(name, t)
Target: Switch control.
name: configured Switch name.switchOff(name, t)
Target: Switch control.
name: configured Switch name.playScene(id, t, scene)
Target: Hue Scene Controller.
scene: imported scene identifier/name for that channel.execute(id, t, parameters)
Target: Custom Handler.
parameters: string understood by the custom service.
Use launchOperation and cancelOperation to control Operations. Light functions offer percentage or byte values as listed above.
Audio Box Script Limitations in 3.5.2
The functions above are registered in the script runtime, but two audio parameters are not passed to Audio Box in the format it expects:
- playMedia start position: the script wrapper forwards its position as a number without converting seconds to the milliseconds expected by Audio Box. A non-zero position therefore does not reliably select the intended point in the file. Use
position = 0to start at the beginning, or set a non-zero start position in the Effect Sequence editor. - enableInput target: the script wrapper sends the player channel under a different attribute name from the one Audio Box reads. Use Enable Input in an Effect Sequence and select the destination Audio Player there. Do not rely on the script call to connect the microphone.
These limitations concern the script wrappers. They do not remove the existing audio playback or microphone functions in the effect editor. Check the actual audio routing and playback when accepting your room configuration.
For light commands, null leaves an optional color or temperature unchanged. In the percentage functions, null intensity also leaves intensity unchanged. Temperature is a relative 0–100 value, not Kelvin. Byte functions require a whole value from 0 to 255 and reject fractional or out-of-range values. On an 8-bit DMX scalar channel the byte is exact; higher-resolution channels scale it to their full range. This is not native 16-bit position input.
The following examples use illustrative project IDs and names. Replace them with the IDs and names in your project:
// Place these calls inside the appropriate callback, such as onActivate.
setVariable("SelectedRoute", 0, "expert");
setLightByte("FunctionLight", 0, null, null, 66);
transitionLight("RoomLight", 0, 0xFF8800, null, 60, 1.5);
launchOperation("Thunder", 0.5, 0, 0);
unlock("FinalDoor", 2);
// A pattern's filename and target must exist in your project.
playPatternByte("CandleLight", 0, "Candle.rxeffect", true, 128, 1.0);
For the effect editor equivalents, see Effect Sequences; for pattern behavior, see Light Patterns; for audio routing and input setup, see Realix Audio Box.
Reading Object State
Returns the current value of an object, whether it’s an Input, Sensor, or RFID object. For outputs, it returns the last value that was set, allowing you to check what the system most recently did
// Get the current state of an object
getState(objectId)
Read-only System values
getState(objectId) returns the current value as its underlying type. Project Variables contain text and can be written with setVariable. The reserved System.* values below are read-only and are updated by Core.
| ID | Type / meaning |
|---|---|
| System.GameState | Text: Stopped or Running. This is a simplified script value: Ready is reported as Stopped, and RunningFailed and both finished states are reported as Running until reset. Use the finished flags below for the result. |
| System.IsFinishedSuccess / System.IsFinishedFailed | Boolean flags for the two finished outcomes. |
| System.Language | Text: selected player language. |
| System.RemainingSeconds | Integer: remaining game seconds. |
| System.GameElapsedSeconds | Integer: game-clock elapsed seconds, including the effect of corrections. |
| System.WallElapsedSeconds | Integer: elapsed wall-clock seconds. |
| System.TotalGameSeconds | Integer: configured maximum game duration in seconds. |
| System.CorrectionSeconds | Integer: game-time correction in seconds. |
| System.TimeRunning / System.IsPaused | Boolean timing flags. |
| System.CompletionPercentage | Number: completion percentage, 0–100. |
| System.SkillLevel | Text: selected skill level; Normal is the default where no level is configured. A required unselected setting can be empty. |
| System.TeamCount | Integer: configured team size, or 0 when not set. |
| System.TeamInfo | Text: entered team information, or an empty string. |
var playerLanguage = getState("System.Language");
var timeRemaining = getState("System.RemainingSeconds");
var route = getState("SelectedRoute");
if (getState("System.IsFinishedFailed")) {
console.log("Game finished after a timeout");
}
An unknown or empty Object ID is logged and returns 0. Do not treat that fallback as proof that a physical input is inactive. Check the ID and any connection errors first.
Logging
Logs a message to the Logic Console, visible during script execution. Ideal for:
- Debugging logic
- Inspecting object state
- Monitoring script behavior in real-time
// Produce a log message
console.log(msg)
In the Designer Logic Console, select the relevant Active or Test configuration. Live shows incoming messages; Load earlier messages can extend it from the current log file. Logfiles lets you select archived files and a period. A fresh Live view does not automatically include file history. See Logics Console for the workspace.
