0 votes
by (120 points)
edited by

I want to have a list with "items" that should set the variable $action to the corresponding "item". This somehow works until i click"attack" for example. Printing $action throws the following error: "attack is not defined".

(set: $actionlist to (a: "attack", "open"))\
(set: $action to "")\
\
(for: each _item, $actionlist)[\
  (print: "(link: '(text: _item)')[(set: $action to " + (text: _item) + ")]")\
]\

2 Answers

0 votes
by (6.2k points)
When it says something is not defined it means the variable is empty. I'm not very good with arrays and can't help you very well with this code, sorry about that, but make sure $action is set to something. You set it to " + (text: _item) + "). What are the random add signs for?
0 votes
by (159k points)

Try the following..

{
(set: $actionlist to (a: "attack", "open"))
(set: $action to "")

(for: each _item, ...$actionlist)[
  (print: "(link: '(text: _item)')[(set: $action to '" + _item + "')]")
]
}

If you look at the (for:) macro documentation you will see that it uses the ... Array Data operator to convert the Array value stored in the story variable into a sequence of parameters for the macro. I also replaced the (text:) macro call with a set of single quotes, one before the 1st closing double quotes and one after the 2nd opening double quote.

...