I'm implementing a combat system that needs to display a list of abilities to the player. Currently, I'm doing this as follows:
/* abilities is an object map field of an object called Character defined in story javascript; _currentTurnOwner is the Character whose turn it is */
abilities = {
"attack" : new State.variables.Ability("Attack"),
"defend" : new State.variables.Ability("Defend"),
"run" : new State.variables.Ability("Run")
}
...
<<for _abilityName,_ability range _currentTurnOwner.abilities>>
<<link [[_abilityName->Combat]]>>
<<run console.log("setting current selected abl to the value of temp var ability, which points to "+_ability.name);>>
<<set $combatArena.currentSelectedAbility = _ability>>
<</link>>
<</for>>//end ability listing loop
The links show the correctly enumerated abilities Attack, Defend, and Run. However, the problem I'm having is that the temporary variable value is not evaluated until the link is clicked, and at that point it holds whatever was last set within the enclosing for loop. Hence, Attack and Defend both log to the console that Run is the current selected ability. What's the best way to handle this situation where code within <<link>> macros generated in a <<for [range]>> loop macro needs to refer back to the relevant object from the range iteration wherein the <<link>> was defined? Is there a way to access the parent <<link>> macro from within nested child macros, perhaps?