Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[Bug] Array and object references don't work in links

Consider
<<set $options to $room[$current].options>>
<<set $ix to 0>>
<<set $opt to $options[$ix]>
[[<<opt.choice>>|$options[$ix].goto][$score += $options[$ix].points]]
<<set $ix += 1>>
<<set $opt to $options[$ix]>
[[<<opt.choice>>|$options[$ix].goto][$score += $options[$ix].points]]
<<set $ix += 1>>
<<set $opt to $options[$ix]>
[[<<opt.choice>>|$options[$ix].goto][$score += $options[$ix].points]]
This code will print out three options.  Only problem is  that they won't work.  The options will display properly, but when the link is clicked the destination and score increment used will be those of the last choice, not those for the choice the user selected.

Why? Well, both $options and $ix get updated with each iteration of the 'flattened' loop, so by the time the final option has been printed they have the values for it (the last line).  The values in the destination and the tail seem not to be resolved until the link is clicked, at which point the variables have the wrong values.

That is to say, it seems to be storing:
[[Option A|$options[$ix].goto][$score += $options[$ix].points]]
...for it to work, it actually needs to store:

[[Option A|$options[1].goto][$score += $options[1].points]]
...or even...
[[Option A|Opt1_dest][$score += 5]]
Should I write up an issue for it?

Comments

  • This looks like the same issue reported in this thread. The problem there is that the variable is evaluated when the link is followed, not when the link is added to the passage HTML. To force earlier evaluation, use the <<print>> macro.
  • Thanks. That fix has some interesting possibilities...
Sign In or Register to comment.