This is an old revision of the document!
The «checkbox» macro lets you offer your reader with a group of checkboxes to choose from. While a <<radio>> set lets the reader choose only one option, checkboxes let the reader choose any combination of options–or none at all!
Note that, in order for the value to be stored, there must be a <<button>> in the passage, and the user must click it.
This code sample:
What would you like to pack? <<checkbox $backpack "shoes">> <<checkbox $backpack "shirt">> <<checkbox $backpack "toothbrush">> <<button [[Go on|go_on]]>>
Creates this set of options:
In this example, the variable $choice is the name for this set of checkboxes. You can set this to any variable name you like.
You see each input has a value–in this example, “shoes,” “shirt,” and “toothbrush.” These are what will be displayed to the reader AND stored in the variable ($choice, as a list separated by commas) to be used in the next passage.
Thus if a reader chooses “shoes” and “shirt” and clicks the button “Go on,” it's the same as telling Twine this:
<<set $choice = ["shirt", "shoes"]>>
You'll notice this looks a little different from the usual variable.
As of version 1.4.2, Twine forces a line break between checkboxes. To work around this, you can place your checkboxes in an HTML table:
<table> <tr> <td>Sound?</td><td></td><td><<checkbox $sound "dialogue">></td><td><<checkbox $sound "foley">></td><td><<checkbox $sound "music">></td> </tr> <tr> <td>Visual effects?</td><td></td><td><<checkbox $visual_effects "red/green">></td><td><<checkbox $color_effects "gradients">></td><td><<checkbox $visual_effects "flashes">></td></td> </tr> </table> <<button [[Begin the Game|Begin]]>>
This code sample creates this:
As of version 1.4.2, there is no option to mark a checkbox as selected before your reader makes their choice.
Hope this helps. If you have questions, please visit the Twinery forum.