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

Setting a max value for a formula?

Simply using max="(number)" doesn't work, so what does?
1552006699

Edited 1552023133
vÍnce
Pro
Sheet Author
Assuming you are working on a custom sheet; you need to include a second attribute for max by adding&nbsp; "_max" to the primary attribute's name.&nbsp; e.g. Foo:&lt;input type="number" name="attr_foo" value="0" /&gt; Max Foo:&lt;input type="number" name="attr_foo_max" value="0" /&gt; Wiki info:&nbsp; <a href="https://wiki.roll20.net/Building_Character_Sheets#Creating_Fields" rel="nofollow">https://wiki.roll20.net/Building_Character_Sheets#Creating_Fields</a> edit: misunderstood the problem: see below.
Didn't work. Formula value still surpasses the max value I set.
1552008587
vÍnce
Pro
Sheet Author
Sorry Joe, I mistakenly thought you were wanting to create an attribute's max value.&nbsp; Sounds like you want to set a "cap" on an attribute value?&nbsp; I think the min/max input attribute only restrict the allowable number range from the end-user.&nbsp; I don't believe they will work if setting the value using a macro/formula.&nbsp; Can you adjust your formula, perhaps using a min value? (<a href="https://wiki.roll20.net/CSS_Wizardry#min.28x.2C_y.2C_z.2C_....29" rel="nofollow">https://wiki.roll20.net/CSS_Wizardry#min.28x.2C_y.2C_z.2C_....29</a>)&nbsp; Otherwise you would probably need some sheetworker code to handle that.&nbsp; Maybe post an example of your code.
1552008965

Edited 1552009013
&lt;input type="number" dir="rtl" name="attr_mmpF" style="color:white;border:#0000c8;background-color:#0000c8;width:49%" value="floor(1+(@{intF}*0.5)+(@{lvlF}*0.5)+(@{emp6a}+@{emp6b}+@{emp6c}+@{emp6d}+@{emp6e}+@{emp6f}))" max="99" disabled&gt; The code works exactly how I want it to, except for the max part. The problem is the max property limits how high i can set the number using the spinner and what I need is a way to limit the value so that the formula cannot make it go past 99 period.
1552010638
vÍnce
Pro
Sheet Author
If you only need the @{mmpF} value for a macro(meaning you only need the value when sent to chat),&nbsp; you can use a group roll.&nbsp; ie [[ { floor(1+(@{intF}*0.5)+(@{lvlF}*0.5)+(@{emp6a}+@{emp6b}+@{emp6c}+@{emp6d}+@{emp6e}+@{emp6f})) ,99}kl1 ]] to cap at 99.&nbsp; Otherwise, I think you'll need to use the min example from the wiki.
The formula is for calculating a stat on the character sheet, in this case Max MP for 1 of the many classes available (hence the F at the end of mmp). I feel that max_xy might do the trick but I cannot figure out how to implement it into my formula. Some assistance there would be appreciated!
1552022674

Edited 1552023035
vÍnce
Pro
Sheet Author
Sorry, just got back from a meeting... So, you only need to use the first example from the wiki since you only need to compare 2 values &lt; input type = "number" name = "attr_min_xy" value = "(((@{x} + @{y}) - abs(@{x} - @{y})) / 2)" disabled &gt; Just substitute your formula for X and use "99" for Y. &lt;input type="hidden" name="attr_min_xy" value="(((( floor(1+(@{intF}*0.5)+(@{lvlF}*0.5)+(@{emp6a}+@{emp6b}+@{emp6c}+@{emp6d}+@{emp6e}+@{emp6f})) ) + 99) - abs(( floor(1+(@{intF}*0.5)+(@{lvlF}*0.5)+(@{emp6a}+@{emp6b}+@{emp6c}+@{emp6d}+@{emp6e}+@{emp6f})) ) - 99)) / 2)" disabled&gt; Now you should have an attribute you can use (If x &gt; y, the result is y, while if x &lt; y, the result is x.) Just rename "attr_min_xy" in the example above to "attr_ mmpF ".&nbsp; Untested, but I think that should solve your problem. edit: changed the example from type="hidden" to type="number" so you can see the result.
1552023283

Edited 1552023336
No worries, I edited in the part you provided in the value property and it did the trick. Thanks!