View Single Post
Mathias
Senior Member
Lone Wolf Staff
 
Join Date: May 2005
Posts: 12,584

Old September 1st, 2009, 12:10 PM
Quote:
Originally Posted by Lawful_g View Post
Here is my example code, for reference

~ If our dexterity bonus is higher than our strength bonus, do nothing and get out now.
var dexterity as number
var strength as number
dexterity = hero.child[aDEX].field[aModBonus].value
strength = hero.child[aSTR].field[aModBonus].value
if (dexterity >= strength) then
done
endif

~ Since our Strength is higher than our dexterity and we passed, iterate through all weapons which are thrown, and subtract dexterity and add strength instead to our attack rolls.

foreach pick in hero where "wCategory.RangeThrow Missing stuff here"
each.field[wAttBonus].value = each.field[wAttBonus].value - dexterity + strength
nexteach
to condense your code, may I suggest the following:

Code:
var bonus as number
bonus = maximum(hero.child[aDEX].field[aModBonus].value - hero.child[aSTR].field[aModBonus].value , 0)
doneif (bonus= 0)
 
foreach pick in hero where "wCategory.RangeThrow & !wCategory.Melee"
eachpick.field[wAttBonus].value += bonus
nexteach
That way, taking the maximum of your difference and 0 means that if STR is greater than DEX, it will add +0 - and your if statement can be compressed into one line with doneif.

Your code was fine, except that you should be using eachpick. instead of each. within your foreach loop (the other will still work, but only because the program still supports legacy code).
Mathias is offline   #6 Reply With Quote