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

Math inside a sheet

So, I thought of a new feature to add to my sheet, but, I can't seem to get the math to work correctly. <td><input type="text" name="attr_Strength" title="@{Strength}" class="short" value="10"/></td> <td><input type="text" name="attr_Stamina" title="@{Stamina}" class="short" value="10"/></td> <td><input type="text" name="attr_Muscle" title="@{Muscle}" class="short" value="10"/></td> <td><input type="text" name="attr_carryweight" title="@{carryweight}" class="sheet-short"  value="(floor((26+(floor(({@{Strength}, @{Stamina}}kh1)/3)*5))*.25))" disabled="true"/></td> <td><input type="text" name="attr_maxpress" title="@{maxpress}" class="sheet-short"  value="((26+(floor(({@{Strength}, @{Muscle}}kh1)/3)*5)))" disabled="true"/></td> So, this probably should be putting out (10) in the first box, and (41) in the second.... but it's putting out, (4215) in the first box and (16861) in the second... Can kh and kl functions not be used in the sheet itself or only in java macros? This isn't going to work so well if I can't write this in like this unfortunately.. Any help would be greatly appreciated :D
1482287208
Finderski
Pro
Sheet Author
Compendium Curator
That type of math is not available for calculated fields in character sheets.  However, you could use a  Sheet Worker  to do that type of calculation (not using kh1, though).
ahh, bummer... I don't know how to utilize sheet workers, so, basic functions it is. :) thanks
1482290325

Edited 1482290567
vÍnce
Pro
Sheet Author
You can use min(a,b) and max(a,b) post by Brian ( <a href="https://app.roll20.net/forum/permalink/917740/" rel="nofollow">https://app.roll20.net/forum/permalink/917740/</a> ) and even more advanced math by Brian ( <a href="https://app.roll20.net/forum/permalink/944536/" rel="nofollow">https://app.roll20.net/forum/permalink/944536/</a> ) min(A, B) with (((@{A} + @{B}) - abs(@{A} - @{B})) / 2) max(A, B) with (((@{A} + @{B}) + abs(@{A} - @{B})) / 2) Basically min(a,b) is like Kl1 and max(a,b) is like Kh1
1482291018
Lithl
Pro
Sheet Author
API Scripter
As Vince points out, kl/kh is not part of the arithmetic available to autocalc fields. However, you can achieve the same functionality (and more) with the correct application of the arithmetic that is &nbsp;available. In the&nbsp; CSS Wizardry thread, I created &nbsp;a post replicating almost the entirety of the JavaScript Math library. Some of the functions are approximations (such as square root), some do not work for every single value (such as sign(x) for x=0), and three cannot be implemented using autocalc (fround, imul, and random), but it's a good resource for autocalc fields.
I'm almost certain at least half of that is klingon lol. I don't know math, and I don't know html, I'm just good with patterns. That stuff ^ I can't follow, because it's a sequential thing, not really a repeating pattern. It's ok though, I found a work around in removing Stamina and Muscle altogether since P.O. Attributes are not relevant to the game anyways :D
1482297479

Edited 1482297568
Lithl
Pro
Sheet Author
API Scripter
I'm not sure what you mean. Instead of: (floor((26+(floor(( {@{Strength}, @{Stamina}}kh1 )/3)*5))*.25)) You can replace the bolded part with the max(A, B) equation above (replacing A with Strength and B with Stamina) to get: (floor((26+(floor((((@{Strength} + @{Stamina}) + abs(@{Strength} - @{Stamina})) / 2)/3)*5))*.25)) The equation is the sum of the two numbers, plus the difference between the two numbers, divided by two. For example, 9 and 15 makes: ((9 + 15) + abs(9 - 15)) / 2 = (24 + abs(-6)) / 2 = (24 + 6) / 2 = 30 / 2 = 15 Let's look at why this is. If a &gt;= b, then max(a, b) = a and: (a + b + abs(a - b)) / 2 = (a + b + a - b) / 2 = 2a / 2 = a If a &lt; b, then max(a, b) = b and: (a + b + abs(a - b)) / 2 = (a + b + b - a) / 2 = 2b / 2 = b