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
This post has been closed. You can still view previous posts, but you can't post any new replies.

New MAX/MIN Math Operators, or allow kh/dl to combine math/rolls

I have a use case where I would like to return the result of a roll plus calculation as 0 if the calculated result is negative. You can't use kh1 for this because it prevents using both rolls and math in the same expression. For example, I would like to roll a 1d20 and add it to a character attribute (which could be negative), and return the result if it is 0 or higher, and return 0 if it is negative. Excel has a function for this called MAX/MIN, that gives the higher/lower value of two inputs. This would be very helpful in Roll20. max(x,y) would the higher value of x or y. In this case I could use MAX(0,myexpression) to make sure that if myexpression's result is negative, it returns 0. min(x,y) would return the lower value of x or y. I could see others wanting this expression for other purposes. Again, this is similar to the kh/dl operators, but works when math and rolls are combined. Another fix for this would be to allow kh/dl to work with combined math/roll expressions.
I believe you could solve this need by still using the kh1 method. [[ {1d20+@{attr},0d0}kh1 ]] By putting 0d0, you are making both side of the comma be dice expressions, which can be calculated using the kh operator. You can also use this method for non-zero numbers, 0d0+5 would compare the die result to 5 and pick the higher. So would 5d1 work to the same end.
Kyle G. said: I believe you could solve this need by still using the kh1 method. [[ {1d20+@{attr},0d0}kh1 ]] By putting 0d0, you are making both side of the comma be dice expressions, which can be calculated using the kh operator. You can also use this method for non-zero numbers, 0d0+5 would compare the die result to 5 and pick the higher. So would 5d1 work to the same end. Thanks Kyle! I'll give this a try later and report if it solves my issue. The expression I want to evaluate to itself or 0, whichever is higher, is a little more complicated, but if I can cheat in a 0d0 or 0d0+(expression) that would be perfect. I'll paste it in when I get to it!
1549987369
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Just as an expansion of Kyle's excellent advice, any of these will work: [[{1d20+[[3d6+56]]+100,0d0}kh1]] [[{1d20+3d6+56+?{Modifier},0d0}kh1]] [[{1d20+56,0d0}kh1]]
1549987435

Edited 1549987778
Here is the expression which I would like to either evaluate to 0 or itself: [[floor(floor(((1*@{power-1-weapon-num-dice})d@{power-1-weapon-dice})+@{power-1-damage})*((((1d20+@{power-1-attack}) - (@{target|Enemy|ac}))*0.1)+1)))]] (Calculation uses the accuracy 1d20 roll compared to target defense and uses that to modify the damage roll, instead of reporting a hit/miss. I would like the minimum damage output to be 0 and not a negative number, so this is the full expression I would like to resolve to itself or 0). It sounds like y'all are saying I can simply couch this whole thing in [[{crazyexpression,0d0}kh1]] and it should work? I'll try when I get home, but I'm worried there's already too much math in there and only the one roll.
1550003066
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yep, all the system cares about is "is there a roll on both sides or are there no rolls at all".