Can an "eachpick" item in a "foreach pick" loop recognize itself as the parent?
I have a question about a FATE Core script I'm writing, but the question is centered around scripting rather than FATE Core, so it makes more sense to me to post it here.
Question: If I include a "foreach pick" loop in an eval script for a stunt, where one of the results will be the parent stunt of the script, is there a way to identify if a particular "eachpick" instance is that same parent stunt?
Context: I have a stunt that offers a refresh bonus, is not unique, and allows multiple ranks. A hero can have five different instances of this stunt, each with its own bonus value. However, according to the rules I'm implementing, only the highest bonus value should apply. The stunt is called "The Catch", so for instance, if a hero has:
The Catch @ 5 pts.
The Catch @ 3 pts.
The Catch @ 1 pt.
The Catch @ 5 pts.
Only 5 points should be applied. I've written the following script which seems to be working so far, but I had to fudge things a bit at the end. In the case above, there are four instances of The Catch. So when I tell the script to find the highest value (5 pts.), and add only the 5 pts, it's doing that four times. Collectively, I end up with 20 pts. instead of 5.
I compensated for this by dividing the highest bonus by the number of instances. With the example above, that gives me 5/4 for each script. But since there are four scripts doing this, I end up with a total of 5.
If there was a way, as I ran through the foreach loop, where every time I found a higher bonus than before, I could query whether or not that bonus belongs to the immediate parent of the script, then I could have only that instance apply its bonus, and I wouldn't have to divide to compensate.
Here's my current script:
I have a question about a FATE Core script I'm writing, but the question is centered around scripting rather than FATE Core, so it makes more sense to me to post it here.
Question: If I include a "foreach pick" loop in an eval script for a stunt, where one of the results will be the parent stunt of the script, is there a way to identify if a particular "eachpick" instance is that same parent stunt?
Context: I have a stunt that offers a refresh bonus, is not unique, and allows multiple ranks. A hero can have five different instances of this stunt, each with its own bonus value. However, according to the rules I'm implementing, only the highest bonus value should apply. The stunt is called "The Catch", so for instance, if a hero has:
The Catch @ 5 pts.
The Catch @ 3 pts.
The Catch @ 1 pt.
The Catch @ 5 pts.
Only 5 points should be applied. I've written the following script which seems to be working so far, but I had to fudge things a bit at the end. In the case above, there are four instances of The Catch. So when I tell the script to find the highest value (5 pts.), and add only the 5 pts, it's doing that four times. Collectively, I end up with 20 pts. instead of 5.
I compensated for this by dividing the highest bonus by the number of instances. With the example above, that gives me 5/4 for each script. But since there are four scripts doing this, I end up with a total of 5.
If there was a way, as I ran through the foreach loop, where every time I found a higher bonus than before, I could query whether or not that bonus belongs to the immediate parent of the script, then I could have only that instance apply its bonus, and I wouldn't have to divide to compensate.
Here's my current script:
Code:
~ Declare variables
var thisbonus as number
var highbonus as number
var catches as number
~ Refund the refresh bonus of this instance of The Catch.
herofield[acRefrBase].value -= field[stNumber].value
~ Initialize variables
highbonus = 0
catches = 0
~ Cycle through each instance of The Catch
~ Find the highest, single bonus value from all instances.
~ Count the number of instances.
foreach pick in hero from Stunt where "thingid.pwrCatch"
thisbonus = eachpick.field[stNumber].value
if (thisbonus > highbonus) then
highbonus = thisbonus
endif
catches += 1
nexteach
~ Apply only the highest bonus value.
~ Since this script runs on all instances, compensate by
~ dividing the highest bonus value by the number of instances.
~ (This is the part that feels awkward)
herofield[acRefrBase].value += (highbonus / catches)