Here's how I dealt with this issue in Shadowrun:
(You can ignore the parts about trtOver and trtReplace - that's needed in Shadowrun to deal with spirit possession, which overrides some of your normal attributes)
All the code from Calc trtFinal is basically repeated in the trtFinal procedure that each of these calls.
(You can ignore the parts about trtOver and trtReplace - that's needed in Shadowrun to deal with spirit possession, which overrides some of your normal attributes)
All the code from Calc trtFinal is basically repeated in the trtFinal procedure that each of these calls.
Code:
<!-- We need a second calculation pass for trtFinal so that things that
depend on the first Calc trtFinal can apply their effects, and then
those effects are incorporated into trtFinal by this script -->
<eval index="4" phase="Traits" priority="6000" name="Calc trtFinal #2">
<after name="Calc trtFinal"/>
<after name="Calc grRating"/><![CDATA[
var normalval as number
var replaceval as number
var overval as number
call trtFinal
if (field[trtOver].value >= 0) then
field[trtFinal].value = overval
elseif (field[trtReplace].value >= 0) then
field[trtFinal].value = maximum(normalval, replaceval)
else
field[trtFinal].value = normalval
endif
]]></eval>
<!-- And a third calculation pass for trtFinal so that things that
depend on the second Calc trtFinal can apply their effects, and then
those effects are incorporated into trtFinal by this script -->
<eval index="5" phase="Traits" priority="8000" name="Calc trtFinal #3">
<after name="Calc trtFinal #2"/><![CDATA[
var normalval as number
var replaceval as number
var overval as number
call trtFinal
if (field[trtOver].value >= 0) then
field[trtFinal].value = overval
elseif (field[trtReplace].value >= 0) then
field[trtFinal].value = maximum(normalval, replaceval)
else
field[trtFinal].value = normalval
endif
]]></eval>
<!-- And a fourth calculation pass for trtFinal so that things that
depend on the third Calc trtFinal can apply their effects, and then
those effects are incorporated into trtFinal by this script -->
<eval index="6" phase="Traits" priority="10000" name="Calc trtFinal Final">
<after name="Calc trtFinal #3"/><![CDATA[
var normalval as number
var replaceval as number
var overval as number
call trtFinal
if (field[trtOver].value >= 0) then
field[trtFinal].value = overval
~since this is the final time we'll calculate trtFinal, we also want to
~tag those things that ended up needing to use the replacement value
if (field[trtOver].value <> normalval) then
perform assign[Helper.ValReplace]
endif
elseif (field[trtReplace].value >= 0) then
field[trtFinal].value = maximum(normalval, replaceval)
~since this is the final time we'll calculate trtFinal, we also want to
~tag those things that ended up needing to use the replacement value
if (replaceval > normalval) then
perform assign[Helper.ValReplace]
endif
else
field[trtFinal].value = normalval
endif
]]></eval>