Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
Create a free account

Simple Maths thats driving me Crazy

Little Background. I was trying to do more complex math's and was planing on using "hidden" inputs for each step, but i wanted to see what was going on while I was changing it, so am using a number thats "disabled" so that it works like a hidden, but that i can see whats going on to check its working. The number's where all coming out crazy and I am now totally confused. I Created a new sheet and reproduced my problem with the below; <span>Max Health </span><input type="number" name="attr_maxhealth" value="20" disabled="true" /><br />     <span>Current Health </span><input type="number" name="attr_currenthealth" value="@{maxhealth}-@{damagetaken}" disabled="true" /><br />     <span>Damage Taken </span><input type="number" name="attr_damagetaken" value="0" /><br /> <br /> <span>currentHealth (works)</span><input type="number" name="attr_test1" value="@{currentHealth}" disabled="true" /><br /> <span>14*14 (works)</span><input type="number" name="attr_test1" value="14*14" disabled="true" /><br /> <span>currentHealth*14 (doesnt)</span><input type="number" name="attr_test1" value="@{currentHealth}*14" disabled="true" /><br /> <span>currentHealth*currentHealth (doesnt)</span><input type="number" name="attr_test1" value="@{currentHealth}*@{currentHealth}" disabled="true" /><br /> <br /> <span>doubleSquare encased</span><br /> <span>currentHealth*14 (doesnt)</span><input type="number" name="attr_test1" value="[[@{currentHealth}*14]]" disabled="true" /><br /> <span>currentHealth*currentHealth (doesnt)</span><input type="number" name="attr_test1" value="[[@{currentHealth}*@{currentHealth}]]" disabled="true" /><br /> <br /> <span>doubleCurley encased</span><br /> <span>currentHealth*14 (doesnt)</span><input type="number" name="attr_test1" value="{{@{currentHealth}*14}}" disabled="true" /><br /> <span>currentHealth*currentHealth (doesnt)</span><input type="number" name="attr_test1" value="{{@{currentHealth}*@{currentHealth}}}" disabled="true" /><br /> <br /> <span>double BOTH! encased</span><br /> <span>currentHealth*14 (doesnt)</span><input type="number" name="attr_test1" value="[[{{@{currentHealth}*14}}]]" disabled="true" /><br /> <span>currentHealth*currentHealth (doesnt)</span><input type="number" name="attr_test1" value="[[{{@{currentHealth}*@{currentHealth}}}]]" disabled="true" /><br /> The top Two that are the simple get number and 14*14 are right and give 14 and 196 respectively, everything else gives either 64 or -100 (I think, It could be bigger but the box is too narrow) What am I doing wrong!
Alan S.
Sheet Author
This is an order of operations issue. let's say you have max health 20 and damage taken 1. since current health is set to max health - damage taken, it's easy to think of it as "19", but it's actually "20-1", since roll20 evaluates attribute calls first and then does the math at the end. so current health * current health isn't "19*19", it's "20-1*20-1".  And since order of operations will resolve the multiplication before the subtraction, you'll end up with -1 when you expected a 361.
I think Alan has the correct diagnosis. The resolution will be to use parenthesis. Either around your `currentHealth` formula, or around `@{currentHealth}` when referenced in other formulas. <div>   <span>Current Health</span>   <input type="number" name="attr_currenthealth" value="(@{maxhealth}-@{damagetaken})" disabled="true" />   </div> <div>   <span>Damage Taken</span>   <input type="number" name="attr_damagetaken" value="0" /> </div> <div>   <span>currentHealth*currentHealth</span>   <input type="number" name="attr_test1" value="@{currentHealth}*@{currentHealth}" disabled="true" /> </div> -or- <div>   <span>Current Health</span>   <input type="number" name="attr_currenthealth" value="@{maxhealth}-@{damagetaken}" disabled="true" />   </div> <div>   <span>Damage Taken</span>   <input type="number" name="attr_damagetaken" value="0" /> </div> <div>   <span>currentHealth*currentHealth</span>   <input type="number" name="attr_test1" value="(@{currentHealth})*(@{currentHealth})" disabled="true" /> </div>
Legend! Thankyou both!