Twine Version: 2.10.0
Sugarcube: 2.37.3
I’m trying to update an object’s properties from one passage and then display those values in another passage. It’s not working. Bill’s strength and agility always remain the same when I go back to the “home” passage. I think this is because each passage creates a new copy of the object in question? What’s the best way to change the value everywhere? Here’s my code.
Passage 1: “home”
<<set $bill = {
name: "Bill",
stats: {
strength: 8,
agility: 7,
},
}>>
<<set $bob = {
name: "Bob",
stats: {
strength: 9,
agility: 6,
},
}>>
<<set $sue = {
name: "Sue",
stats: {
strength: 10,
agility: 5,
},
}>>
<<set $activePlayers to [$bill,$bob,$sue]>>
Bill Strength: $bill.stats.strength
Bill Agility: $bill.stats.agility
<<for _i to 0; _i lt $activePlayers.length; _i++>>
<<capture _i>>
<<link $activePlayers[_i].name>>
<<set $target to $activePlayers[_i]>>
<<set State.variables.target = $target>>
<<goto "WhichStat">>
<</link>>
<</capture>>
<</for>>
Passage 2: “WhichStat”
Choose a stat to increase for $target.name:
<<set _statKeys to Object.keys($target.stats)>>
<<for _i to 0; _i < _statKeys.length; _i++>>
<<link _statKeys[_i]>>
<<capture _i>>
<<set $target.stats[_statKeys[_i]] += 1>>
<<goto "home">>
<</capture>>
<</link>>
<</for>>