0 votes
by (190 points)
closed by
I'm using Sugarcube's new Listbox macro to set a variable. The player heads to a screen from the menu option in the sidebar, is presented with the listbox, and returns to the game with the return macro.

This works fine except for one thing: going back to the menu presents the listbox with the first option pre-selected, meaning that if they want to change any options, they need to change all options. I tried to put the listbox in the sidebar, but heading to a new passage also shifts the listbox (and thus the variable) to the first option.

Is there a way to get the listbox to "remember" the selected option between passages or trips to the menu, or to have it default to the current set variable? The only thing that comes to mind is using "selected" and different versions of the listbox based on the current variable, but I'm hoping there's something a little less redundant and a little more elegant.
closed with the note: Question answered.

2 Answers

+2 votes
by (68.6k points)

That's a bit more difficult to do than I'd like.  I'll see about improving that in future versions.

For now, you may combine the selected keyword with backquote expressions to forcibly select the appropriate option.  For example, something like the following should work:

<<listbox "$variable">>
	<<option "LabelA" "A" `$variable is "A" ? "selected" : ""`>>
	<<option "LabelB" "B" `$variable is "B" ? "selected" : ""`>>
	<<option "LabelC" "C" `$variable is "C" ? "selected" : ""`>>
<</listbox>>

 

by (190 points)
It works! Thanks so much!
by (68.6k points)
You should probably select this answer if it met your needs. :)
0 votes
by (44.7k points)

Use TheMadExile's solution (which he posted while I was working on this cheeky ).

...