Like, this:
(set: $food1 to (datamap: "name", "beef", "calories", "300"))
(set: $food2 to (datamap: "name", "sausage", "calories", "400"))
(set: $foodid to (either: 1, 2))
(print: ("$food"+$foodid')s name)
Which would result in a 50% chance to show beef and a 50% chance for sausage.
My question lies in the concatenation of the 'string' $food with the actual value of the variable $foodid, turning the result into the correct variable $food1 or $food2.
If it's not possible, a workaround would be nice.
The only alternative I see right now is working with huge lists of "if" statements ... not pretty!
Thank you!!
Comments
You could use the (either:) macro to select a datamap instead of a number like so:
Thank you so much for your input; the idea of using an aggregate variable (like $currentItem) was absolutely mindblowing!
If you don't mind a follow up question; any idea how to go back from the aggregate to the original variable?
To give a little more context; I'm working on a screen with a table with a list of items which are all datamaps, like above. Clicking on one item would go to a detail screen where you can change the item's properties.
I could make a specific passage per item, but that would quickly get unmanageable.
So basically, with the click: command, I can go to a single screen and show the relevant properties of the chosen item.
But if I change some properties in this new screen; how do I get back to the original screen?
So, how do I do the following:
(set: $food1 to $currentItem)
... considering that this new screen doesn't really know which original item was placed into the currentItem variable. (so after leaving the screen, how does the code know that it has to update the changes made into $currentItem, into $food1 or $food2 or $foodx)
Thank you again!
The following example consists of three passages (startup tagged, Table, Detail)
a. Assign a value to $original, this needs to be done either before the Table passage or in such a way that viewing the Table passage a second time does not reset the $original variable. I am going to use a startup tagged passage to do this. b. Table passage, which in this example is the story's first passage. c. Detail passage: