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

Min of two values

Feels like a pretty basic question, so hopefully easy to answer! I want an input field to return the lowest value out of 1 and a numerical attribute. I.e. If the attribute is 1 or higher then the value should be 1, otherwise 0. How is this done?
1609975688
GiGs
Pro
Sheet Author
API Scripter
The best way would be a sheet worker, but it'd hard to post code without knowing what attributes are involved - the attribute whose value you want to checkj, and the attribute where the modified value is displayed. There's a Math.max(attribute_name,1) function that would do the trick, but this only works inside a sheet worker.
Thought it must be an SW thing. The attribute with the variable value (0+) is @{armour1}. The attribute name for the minimum of (1,@{armour1}) is @{armbin1}. Much appreciated!
1610024307
GiGs
Pro
Sheet Author
API Scripter
Try this. If your sheet doesnt have a block starting with  <script type="text/worker"> you'll need to create one that looks like <script type="text/worker"> </script> Then put the following code inside that block. If such a block already exists, use that one-  dont create a new one. on('change:armour1', () => {     getAttrs(['armour1'], values => {         let armour = +values.armour1 || 0;         let bin = Math.max(1, armour);         setAttrs({             armbin1: bin         });     }); });
Perfect, thanks!!