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.

Minimum/maximum values

For a lot of systems, there's caps on stats and skills and other little doodads. No skill may be higher than 60 even after modifiers, your armor value can't be negative, and your DEX bonus to AC is capped by your armor. There's nothing to allow this, though, and it's causing some headaches for both character sheet creators and average joes trying to figure out armor piercing in attack macros. It'd be nice to have something like min(0|floor(@{DEX-mod}/2)) or max(@{armor-ac}|@{DEX-mod}) or minmax(0|10|@{dicepool})d6.
1402631046

Edited 1402631307
Lithl
Pro
Sheet Author
API Scripter
((A + B) + |A - B|) / 2 is equivalent to max(A, B). So, you could use ((@{armor-ac} + @{DEX-mod}) + abs(@{armor-ac} - @{DEX-mod})) / 2 to get max(@{armor-ac}, @{DEX-mod}). Similarly, ((A + B) - |A - B|) / 2 is equivalent to min(A, B). So, you could use (floor(@{DEX-mod) / 2) - abs(floor(@{DEX-mod} / 2))) / 2 to get min(0, floor(@{DEX-mod} / 2))... however it's worth pointing out that unless DEX-mod is negative, the result will always be 0, and if DEX-mod is negative, the floor function won't work as expected. I've documented this in the CSS Wizardry thread in the Character Sheets forum.
I think you got those two switched around. The max function should be finding the lower of the two values (can't go above a given value), while the min should be finding the higher (can't go below a given value). That's useful though, that'll at least be useful until something not quite as ugly can come along. I'm not quite sure how the floor function isn't working as expected, I just tested it and got a logical result. It rounds down.
1402649448
Lithl
Pro
Sheet Author
API Scripter
Helmic said: I think you got those two switched around. The max function should be finding the lower of the two values (can't go above a given value), while the min should be finding the higher (can't go below a given value). That's useful though, that'll at least be useful until something not quite as ugly can come along. I'm not quite sure how the floor function isn't working as expected, I just tested it and got a logical result. It rounds down. That's not the definition of min and max used by... well, any language I've come across. max(x, y) returns x if x > y or y if y > x, and the reverse for min(x, y). Regardless, both options are available to you, so you can use what you need. The floor function rounds towards negative infinity, not towards zero (-1.5 becomes -2, not -1). This isn't what people are usually expecting, since it's the opposite of what the function does for positive numbers (1.5 becomes 1). However, if rounding towards negative infinity is what you want, then it's certainly the appropriate function to use.
No, he's got it right from a math perspective. The standard max function returns the highest value in the given list/args; min returns the lowest. You're thinking of max() like a function that sets the maximum value, but max() sets a lower bound and min() sets an upper bound. The reason is that if you try to use max(x,5) to set an upper bound, and pass in x=6, it will return 6, whereas min will return the bound as soon as x==bound. upperCap=min(maxValue,value), lowerBound=max(minValue,value).