15. Feed an Array into a list box
A list box can read its contents from an Array and write the player’s selection to another variable. That is useful for a clue notebook, a list of known topics or a puzzle that asks the player to choose an answer.
Keep the contents and the selection separate. The contents variable holds every available item. The selection variable holds the ID of the one the player picked.
1. Create an Array variable, ID clue_options, Name Clue Options. Leave Blank At Start off.
2. Enter the JSON below as its Initial Array Value. Apply and save.
3. Use the String variable last_choice from Chapter 6 for the selected ID. It can start blank/null.
[
{"id":"diagram", "text":"Clock diagram"},
{"id":"socket", "text":"Winding socket"}
]Connect the GUI element#
1. In GUI Designer, add or select a List Box element.
2. Open Type Settings and find List Box Content & Behavior.
3. Set Item Source to array. Keep Allow Multiple Selection off for this example.
4. Set Selected Item Variable to last_choice.
5. Under Array Source, set Array Variable ID to clue_options. Save the project.
The small {...} entries are dictionaries inside an Array. You still choose Array in Variable Designer; there is no separate Dictionary Value Type in this release.
The entries can also carry supported optional fields such as iconAssetId and disabled. Use a stable item ID that makes sense to your conditions. The display text can be more descriptive than that ID.
Figure 20. During play, the label resolves last_choice to diagram after Clock diagram is selected.
