So, your corrected code mostly works for me, but there are still some issues – for example, clicking both “Alice the Bloodied” and “Blood the Aliced” sends me to the stat screen for Blood the Aliced. I honestly don’t know why this happens, perhaps it’s because the code uses repeated temporary variable names in the same passage? Anyway, I wrote a new version of the code that does what you originally asked about.
If I understood correctly, you wanted links with names based on team, drawn from an array, and the ability to increase win numbers permanently for a given character. I had issues when applying one widget to two arrays (basically, when adding a win, I had to first set $side to either $gladiators or $opponents and then increase the win at a certain index of the given side, but this caused the exact problem you were struggling with – only the variable within $side got increased, not the one in $gladiators/$opponents, and everything went back to 0 upon reloading the passage). I put all of the characters into a single “gladiators” array and added a “side” property to the objects so you can tell if someone is an ally or an opponent. Alternatively, you could just go for separate widgets and separate stat screens for each of the sides. (EDIT: That is, make a showLinksGladiators and showLinksOpponents widgets that lead to, respectively, the StatScreenGladiators or StatScreenOpponents passages).
I̶ ̶a̶l̶s̶o̶ ̶g̶a̶v̶e̶ ̶t̶h̶e̶ ̶c̶h̶a̶r̶a̶c̶t̶e̶r̶s̶ ̶t̶h̶e̶ ̶"̶n̶a̶m̶e̶"̶ ̶a̶n̶d̶ ̶"̶n̶a̶m̶e̶f̶u̶l̶l̶"̶ ̶p̶r̶o̶p̶e̶r̶t̶y̶,̶ ̶a̶s̶ ̶I̶ ̶t̶h̶i̶n̶k̶ ̶i̶t̶’̶s̶ ̶e̶a̶s̶i̶e̶r̶ ̶t̶o̶ ̶s̶t̶o̶r̶e̶ ̶t̶h̶e̶ ̶f̶u̶l̶l̶ ̶n̶a̶m̶e̶ ̶i̶n̶ ̶t̶h̶e̶ ̶o̶b̶j̶e̶c̶t̶ ̶t̶h̶a̶t̶ ̶c̶o̶n̶s̶t̶r̶u̶c̶t̶ ̶i̶t̶ ̶u̶s̶i̶n̶g̶ ̶a̶ ̶w̶i̶d̶g̶e̶t̶.̶
Anyway, in StoryInit I have:
<<set $gladiators to [
{
'name':'Alice',
'nick': 'The Bloodied',
'wins':0,
'team':'green',
'side': 'allies',
}, {
'name':'Bob',
'nick': 'Wolfhound',
'wins':0,
'team':'blue',
'side': 'allies',
}, {
'name':'Blood',
'nick': 'The Aliced',
'wins':0,
'team':'red',
'side': 'opponents',
}, {
'name':'Wolf',
'nick': 'Bobhound',
'wins':0,
'team':'blue',
'side': 'opponents',
}
]>>
Then in a widget-tagged passage there’s this one widget:
<<widget "showLinks">>
<<for _i to 0; _i lt _args[0].length; _i++>>
<<capture _i>>
<<if _args[0][_i].team == "green">>
<span class = "green"><<link "_args[0][_i].name _args[0][_i].nick" "StatScreen">><<set $chosen to _i>><<set $side to _args[0]>><</link>></span>
<<elseif _args[0][_i].team == "blue">>
<span class = "blue"><<link "_args[0][_i].name _args[0][_i].nick" "StatScreen">><<set $chosen to _i>><<set $side to _args[0]>><</link>></span>
<<elseif _args[0][_i].team == "red">>
<span class = "red"><<link "_args[0][_i].name _args[0][_i].nick" "StatScreen">><<set $chosen to _i>><<set $side to _args[0]>><</link>></span>
<</if>>
<</capture>>
<</for>>
<</widget>>
In the passage named Start, there’s only
<<showLinks $gladiators>>
And finally, in the StatScreen passage:
This is one of your $gladiators[$chosen].side, $gladiators[$chosen].name $gladiators[$chosen].nick of team $gladiators[$chosen].team who won $gladiators[$chosen].wins time(s).
<<link 'Make them win once more' 'StatScreen'>>
<<set $gladiators[$chosen].wins++>>
<</link>>
<<link 'Return to lists' 'Start'>><</link>>
This does what you wanted while also trimming down the code (I admit I used a maybe not-so-elegant if-statement to select the colour of the links, as with only 3 I think your wrapper widget was needlessly complicated. With more colours, your method may be better).
EDIT: For the coloured links in the example to work, you have to include the following in the story stylesheet:
.red a {
color: red;
}
.green a {
color: green;
}
.blue a {
color: blue;
}