Toggle Button example (checkBox)
- Last UpdatedDec 06, 2023
- 1 minute read
A toggle button is a stateful button, or in other words, a switch. A switch is characterized by its ability to maintain its state until the button is pressed again.
Code example
This is an example of a script that implements a switch.
<!-- button structure -->
<button name="toggle" show="true" position="100 100" size="40 40" >
<layer>
<rect show="true" image="normal.png" order="5" position="0 5" size="40 30"/>
<text show="true" text="OFF" font="Baveuse,true,40" format="Left Up" order="2" position="60 0" size="400 50" color="1 1 1 1"/>
</layer>
<layer>
<rect image="selected.png" order="5" show="true" position="0 5" size="40 30" />
<text show="ON" text="%text%" font="Baveuse,true,40" format="Left Up" order="2" position="60 0" size="400 50" color="0 0.9 0 1"/>
</layer>
</button>
<!-- internal temporary variable -->
<define variable="state" value="false"/>
<!-- state control block -->
<command name="checkState">
<setField field="toggle.selected" value="true" condition="state==false" />
<setField field="toggle.selected" value="false" condition="state==true" />
<setVariable variable="state" value="@toggle.elected@" </command>
<!-- to button click is connected the check state command execution -->
<route from="toggle.mouseDown" to="checkState.execute">