Different stimuli per condition
Show one stimulus in condition A, another in condition B. The if-toggle on a state-listening action does it — no custom code required.
Goal
In one experiment, half the trials (or half the participants) see stimulus A, the other half see stimulus B. The choice has to be tied to a LUIDA condition variable, not a coin flip in your script.
Smallest setup
- A LUIDA scene with at least one trial state.
- Two stimulus GameObjects in the scene (
Stimulus_AandStimulus_B), both with the LUIDA state-listener component attached. - The Configure experiment automation editor open at
LUIDA › Configure experiment automation.
The recipe
Declare the variable
Open the Variables tab. Decide whether you want this to vary within each participant or between participants:
- Within-subjects — every participant sees both stimuli (in random order, across trials). Add a within-subjects variable named e.g.
stimwith valuesA,B. - Between-subjects — each participant only sees one stimulus across all their trials. Add a between-subjects variable named e.g.
stimwith valuesA,B. LUIDA's balancer alternates assignments across sessions.
Save the variables config. Trial count auto-recalculates.
Hide both stimuli by default
In the State-listening Items tab, find the row for Stimulus_A and the column for the trial state. Under On State Start, add a HideItem() action. Do the same on Stimulus_B.
Now both stimuli are hidden when the trial begins.
Conditionally show each stimulus
In the same Stimulus_A cell, under On State Start, add a second action: ShowItem(). Then click the if toggle on that action row. Configure:
- Variable:
stim - Equals:
A
The generated code becomes:
HideItem();
if (CONDITION["stim"] === "A") {
ShowItem();
}Repeat for Stimulus_B, gated on CONDITION["stim"] === "B".
Clean up on state exit (optional but good hygiene)
In the same row for each stimulus, under On State Exit of the trial state, add an unconditional HideItem(). This guarantees a clean slate going into the next trial regardless of which branch fired this trial.
Press Play. On each trial, LUIDA picks the next CONDITION["stim"] (alternating A/B with random shuffling, by default), and only the matching stimulus's ShowItem() fires.
Why this works
CONDITION is the per-trial variable dictionary that LUIDA fills in from your variable declaration before each trial begins. The if toggle on the state-listening editor wraps the action in a CONDITION[var] === value check, executed inside the same lifecycle slot — so the gate happens at the moment of action firing, with the current trial's variables.
HideItem / ShowItem are global state writes on the item itself (isVisible), networked to all clients in the Cluster instance. Both branches of your "if" race-free, because the editor generates them as straight-line code inside a single lifecycle handler — there's no await or two-frame gap where both stimuli could briefly be visible.
For background on within vs between assignment, see Concepts → Within vs between subjects. For the balancer that assigns between-subjects variables across sessions, see Concepts → Conditions, sessions, participants.
Variants
More than two stimuli. Use values A,B,C,D. Add four hidden stimuli, each with a ShowItem() gated on its matching CONDITION value. Scales linearly.
Stimulus is a property of one shared GameObject, not a separate one. Use a single Stimulus GameObject and toggle its text or texture instead of its visibility:
// On State Start, in a Customized Action
if (CONDITION["text"] === "Red") {
SetText("Red");
} else if (CONDITION["text"] === "Blue") {
SetText("Blue");
}The Stroop tutorial uses this pattern for the colored words. See Reference → SetText and Reference → SetChildPosition for related single-item-multi-config patterns.
Combine with a second variable. A 2×2 design — font: R, B × text: Red, Blue — gives four cells. Show your Stimulus once, but configure it with a Customized Action that reads both CONDITION["font"] and CONDITION["text"]. This is exactly Tutorial 2's setup.
Per-condition avatars instead of per-condition stimuli. Conceptually identical pattern, but use AssignAvatarToParticipant instead of ShowItem. See the unique-avatar-per-participant cookbook.
Where to go next
- Tutorial 2 → Stroop Effect — within-subjects worked example with multiple variables.
- Concepts → Within vs between subjects — when to choose which.
- Reference → CONDITION — the per-trial variable dictionary.
- Reference → Actions: conditional execution — the
iftoggle's underlying mechanism. - Editor → Variables tab — declaring within/between variables.