User Tools

Site Tools


checkbox

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

checkbox [2014/09/22 22:14]
ateyourlembas Details for how to get values back out of a list
checkbox [2017/10/09 20:39]
Line 1: Line 1:
-====== <<​checkbox>>​ ====== 
  
- 
-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: 
- 
-{{:​twine_checkbox_default.png?​nolink|}} 
- 
-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 = ["​shoes",​ "​shirt"​]>>​ 
- 
-You'll notice this looks a little different from the usual variable. That's because the values chosen by the reader are stored in the order you provided them in a "​list."​ The way to get stuff back out of a list is by asking for it by its position. In this case: 
- 
-$choice[0] is "​shoes"​ 
-$choice[1] is "​shirt"​ 
- 
-Note that the position starts at 0. 
- 
- 
-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: 
- 
-{{:​twine_checkbox_table.png?​nolink|}} 
- 
- 
-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 [[http://​twinery.org/​forum/​index.php/​board,​2.0.html|Twinery forum]]. 
checkbox.txt ยท Last modified: 2017/10/09 20:39 (external edit)