+1 vote
by (160 points)

I have an array of options.  I want the user to indicate one of those options as preferred. I'll use that later in the program.

I attempted this by making a radio button for each array element. The button's value represented the index of the array.  Then I go to the next passage and use the information.  However, the radioButton behavior is not working like I expected,  the index identifier is Null/None (not sure what python None equivalent is in Javascript)

Here's simple demo passages to show what i mean:

Passage: Demo

<<set $names to ["mike", "matt", "dave", "bill"]>>

<<set $nameIndex to "not set">>
<<for _i to 0; _i lt $names.length; _i++>>
<<print (_i + 1) + ". " + $names[_i]>>
<<radiobutton "$nameIndex" $_i>>
<</for>>

[[demo2]]

Passage: demo2

Hello
<<print $names>>
<<print $nameIndex>>
Done.

 

The result I get after choosing one of the names and going to demo2:

Hello
mike, matt, dave, bill

Done.

 

I'm wondering if I'm misunderstanding interactive Macros.  Or perhaps there is a better way to achieve these kinds of things?  This could well be a kludge -- happy to use better cookbook recipe.

 

Thanks

 

 

 

1 Answer

0 votes
by (159k points)
selected by
 
Best answer

Simply remove the $ character before the temporary variable reference being used as the second parameter of the <<radiobutton>> macro and it will work.

<<radiobutton "$nameIndex" _i>>

 

by (160 points)
Thank you.  That did work.   Now obvious to me that I was prefixing a temp-variable with an extraneous 'permanent variable' (?) prefix.  Oops.
...