Hello! I have a question about how to write a widget that can dynamically modify the value of an object key. Say I have an array of “players” and they all have the same general template that looks like this.
<<set $players to []>>
<<run $players.push({
head : {
health : 100,
conditions : []
},
torso : {
health :100,
conditions : []
},
leftArm : {
health :100,
conditions : []
},
rightArm : {
health :100,
conditions : []
},
leftLeg : {
health :100,
conditions : []
},
rightLeg : {
health :100,
conditions : []
},
})>>
Now I want to create a widget, something like “playerAttackTest” that has two arguments, args[0] being the index number of the player being attacked, and _args[1] being the region that will be damaged.
I could do something like this
<<switch _args[1]>>
<<case "head">>
<<set $players[_args[0]].head.condition -= 1>>
<<case "torso">>
<<set $players[_args[0]].torso.condition -= 1>>
<<case "leftArm">>
<<set $players[_arg[0]].leftArm.condition -= 1>>
<<case "rightArm">>
<<set $players[_args[0]].rightArm.condition -= 1>>
<<case "leftLeg">>
<<set $players[_args[0]].leftLeg.condition -= 1>>
<<case "rightLeg">>
<<set $players[_args[0]].rightLeg.condition -= 1>>
<</switch>>
But this feels sort of cumbersome and rigid. I am wondering if there is something that could just take _args[1], use it to look for the object key in the specified object, and then modify its corresponding value. Thank you for any help you can provide!