Hi,
I'm using Sugarcube 2, and I'm display a list of clothing that the user can choose to wear using a <<for>> loop and accessing an pre-configured array variable
eg. (formatted to aid readability)
<<for ...>>
<<set $csobj=...>>
$csobj.name
<<click "Wear">>
<<wearClothing $csobj.name>>
<<replace "#clothing_selector">>
<<display "Clothing Selector">>
<</replace>>
<</click>>
<</for>>
The list displays ok, but clicking any "Wear" link acts as if the last item was clicked. This is because the reference to $csobj.name in the <<wearClothing>> macro tag is being stored as a reference, rather than the current value.
I need to somehow have <<wearClothing>> execute passing the name of the clothing item it corresponds to.
Help please?
Comments
You need to use a <<print>> macro to dynamically generate each <<click>> macro and its contents. Note the usage of single quotes to build the String being passed to the <<print>> macro and that the value of $csobj.name is being wrapped in double quotes.
note: The above code was not tested because I don't know what the <<wearClothing>> macro does.