ON/OFF Toggle Button β
Two buttons (show hood, hide hood) are easy. One button that alternates needs the item to remember its state. That is exactly what a variable and a condition do.
We will build a button that shows and hides a jacket's hood.
You need: a jacket target with a link named hood, a HUD with a prim named hood_toggle, and [add-on] - Conditions & Variables - 1Click in the HUD.
1. Create the variable β
Click the orange tools button (bottom left) β
{ }.Create New Variable: Type String, Name
hood, Initial valueON.Confirm and close the panel.
2. The condition β
Click
hood_togglein the button list to create its function, and open it.Add Condition: Field
$hood, Operator==, ValueON. Save.On the condition's card click Success. The branch opens. Add:
- Change Variable:
$hood, Set,OFF - Transparency: Jacket, link
hood, faces All, alpha0.0
- Change Variable:
Go back, click Failure on the condition's card. Add:
- Change Variable:
$hood, Set,ON - Transparency: Jacket, link
hood, faces All, alpha1.0
- Change Variable:
3. Build and test β
Build, wear copies, click the button: the hood disappears; click again: it is back.
hood_toggle
ββ Condition $hood == ON
ββ success β $hood = OFF Β· Transparency hood 0.0
ββ failure β $hood = ON Β· Transparency hood 1.0Why the variable starts as ON β
The hood is visible when the customer first wears the jacket, so the state must say ON. If your default is hidden, start with OFF and swap the branches.
Keep the HUD in sync β
Add an Attach event with Transparency hood 1.0 and Change Variable $hood = ON, so a fresh attach always starts from a known state (variables also reset at every Build, but not when the customer re-attaches).
The same pattern forβ¦ β
| Goal | Success branch | Failure branch |
|---|---|---|
| Lamp switch | Point of Light ON, $light = ON | Point of Light OFF, $light = OFF |
| Music | Sound Loop, $music = ON | Sound Stop, $music = OFF |
| PBR toggle | PBR On/Off ON, $pbr = ON | PBR On/Off OFF, $pbr = OFF |
| Highlight active | Glow 0.2, $sel = ON | Glow 0, $sel = OFF |
Three or more states β
Use an integer variable ($mode = 0) and chain conditions: $mode == 0 β mode 1 actions and $mode = 1; failure branch holds $mode == 1 β mode 2 and $mode = 2; its failure holds the last mode and $mode = 0.