Member
Join Date: Jun 2012
Posts: 65
|
Can someone please help make this work?
Under the trait bonus field I want the value to equal CO+CO+EN divided by 3 Is there a part of forum dedicated to poor scripters who lack talent? <!-- Health Trait --> <thing id="trHealth" name="Health" compset="Trait" isunique="yes" description="Description goes here"> <fieldval field="trtAbbrev" value="Hlth"/> <tag group="explicit" tag="1"/> <tag group="User" tag="Power"/> <!-- Calculate the Health trait as appropriate --> <eval value="1" phase="Traits" priority="4000"> <before name="Derived trtFinal"/> <after name="Calc trtFinal"/><![CDATA[ field[trtBonus].value += #trait[attrPE] + #trait[attrCO] + #trait[attrCO] / 3 ]]></eval> </thing> |
#1 |
Senior Member
Lone Wolf Staff
Join Date: May 2005
Posts: 13,214
|
Code:
field[trtBonus].value += (#trait[attrPE] + #trait[attrCO] + #trait[attrCO]) / 3 Something else you should look at: at the top, you say that you want it to be EN + CO + CO, but your script appears to have PE + CO + CO. |
#2 |
Member
Join Date: Jun 2012
Posts: 65
|
Sorry but it IS PE. (Physical Endurance ) not so worried about abbreviation as formula. How SHOULD it look? Thanks!
EDIT: OK what you said helped me work it out by dividing Each attribute separatly. Thanks! Last edited by tooley1chris; June 21st, 2012 at 09:21 AM. |
#3 |
Senior Member
Volunteer Data File Contributor
Join Date: Dec 2008
Posts: 523
|
You don't need to divide each by 3 and sum them (though that does work more or less).... use Parenthesis (just like in Algebra) to control order of operations... as Mathias put above () around the addition will cause the values to add before they are divided.
|
#4 |
Senior Member
Lone Wolf Staff
Join Date: May 2005
Posts: 13,214
|
Actually, you probably don't want 1/3's hanging around, either.
What direction is it supposed to round fractions? This will give you round down: Code:
field[trtBonus].value += round((#trait[attrPE] + #trait[attrCO] + #trait[attrCO]) / 3,0,-1) Code:
field[trtBonus].value += round((#trait[attrPE] + #trait[attrCO] + #trait[attrCO]) / 3,0,1) |
#5 |
Senior Member
Lone Wolf Staff
Join Date: May 2005
Posts: 13,214
|
Just in case you have trouble with those (I've had trouble with parentheses inside round() before), here are versions of those that are more reliable:
round down: Code:
var healthtot as number healthtot = (#trait[attrPE] + #trait[attrCO] + #trait[attrCO]) / 3 field[trtBonus].value += round(healthtot,0,-1) Code:
var healthtot as number healthtot = (#trait[attrPE] + #trait[attrCO] + #trait[attrCO]) / 3 field[trtBonus].value += round(healthtot,0,1) |
#6 |
Member
Join Date: Jun 2012
Posts: 65
|
I'm trying to figure out how to spell that sound your lips make when you rapidly rub your finger up and down while humming. WOW but that's another language! Thanks for the rounding script. That's really helping with the extra points here and there! For those of you kind enough to answer my queries BEWARE! I now have you on speed dial for future reference! Haha
|
#7 |
|
|