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

How do I get a calculation that can't be lower than 0?

1435342682
Axel
Pro
Sheet Author
How can I phrase a calculation in a Roll20 character sheet to get a value that is never lower than 0? I'd prefer an If-function, but what I want is this: A - B = C, where C must be 0 if A is lower than B. I've looked at D&D sheets that have a maximum Dex-bonus for AC, but I can't quite figure out how it works. I'd appreciate any assistance.
1435344046
The Aaron
Roll20 Production Team
API Scripter
You can use the Grouping syntax for this: [[ {(A-B),0}kh1 ]] Some things to remember: { } Defines a group. You can have 1 or more things in a group. By default, they will be summed. [[ {2,3} ]] will be 5. Items in a group must be either dice rolls or numbers, you can't have both. If you have dice and you need to specify a constant, you can use 0d0 for 0, or #d1 for some #, like 5d1 for 5. k# Modifies the group to be keeping some values from the set, the # determines how many. Alternatively, you can use d# to mean drop # values. h Modifies the keeping instruction to keep (or drop) from the highest end ( h is the default behavior for keep if it is omitted) You can also use l to keep (or drop) from the lowest end ( l is the default behavior for drop if it is omitted)
1435344669
Axel
Pro
Sheet Author
Thank you! That makes sense.
1435344872
Diana P
Pro
Sheet Author
If you need a math-only solution for an auto-calc field, you can use the max calculation: If x &gt; y, the result is x, while if x &lt; y, the result is y (((@{x} + @{y}) + abs(@{x} - @{y})) / 2) If you ever need the min value instead, that is (((@{x} + @{y}) - abs(@{x} - @{y})) / 2) . from the CSS-Wizardry thread (<a href="https://app.roll20.net/forum/post/882997/#post-944536" rel="nofollow">https://app.roll20.net/forum/post/882997/#post-944536</a> ) On the 3.5 character sheet, I used a much more complicated equation which handles comparing negatives to each other better (and because I needed 'give me C if A is bigger than B else give me B'). If you want that one, let me know and I'll simplify it back down for you. :) Hope that helps.
1435488371
Axel
Pro
Sheet Author
Ok, so what is the difference then? Is there a benefit of using a math-only solution?
1435510784
Diana P
Pro
Sheet Author
Math-only solutions are for parts of character sheets where you can't use a roll. Ie calculating the dexterity bonus from the base dexterity to display it on a character sheet. Or calculating whether the dex bonus or the max dex bonus from armor is higher. Those calculation fields built into a character sheet can't/don't use rolls for their calculations so using the kh1 roll syntax doesn't work; you'd just get to see the equation. If what you are doing is part of a roll or a macro, the kh1/kl1 solution is superior; it's easier to read if nothing else. I wasn't certain if you were working on building a custom character sheet (and so might need a math-only solution) or working on a macro to run from a character sheet. As a Mentor, it could be either. :D
1435524297
Axel
Pro
Sheet Author
I'm trying to make a custome character sheet. I guess I shall have to try to figure out how to use the formula you provided Diana, since this is for an auto-calculating field. Thank you your the assistance. The formula is meant to calculate encumbrance penalties. In the system I'm using, characters suffer a -1 speed penalty per 50 units of weight carried in excess of their carrying capacity. This is one reason why I need the formula.
1435525974
Diana P
Pro
Sheet Author
*nod* If you are wanting to make sure that your delta between the carrying capacity and the current weight carried is never negative (this will give a zero if your delta is negative: (((A + 0) + abs(A - 0)) / 2) where A is Current Weight Carried - Weight Capacity Limit Hope that helps. :)
1435593341
Axel
Pro
Sheet Author
Indeed it helps tremendously! Thank you!