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

Referencing a Value from a Number Range

Hello again, folks! So I'm currently attempting to have have a readonly text input reference a list of Values based on a number within a hidden element based on a range.  Specifically, I'm creating a sheet for a game based in the Basic Roleplaying system which has a number of tables that rely on a range of values.  In this particular case, I want a text box to display the relevant Damage Bonus based on the combination of the Strenght and Size scores.  The table is as follows: 2 to 12 = -1d6 13 to 16 = -1d4 17 to 24 = none 25 to 32 = +1d4 33 to 40 = +1d6 41 to 56 = +2d6 and so on.  At present, the html for this particular section is: <span class="label dmgbonus" value="Dmg. Bonus"></span> <input type="hidden" name="attr_dmgcalc" value='(ceil(@{strength_base} + @{size}))'/> <input type="text" class="content dmgdis" name="attr_damage_display" readonly/> Essentially, I need for the input with "attr_damage_display" to display the appropriate damage modifer (none, -1d4, -1d6, etc.) which would be pulled based on the value of "attr_dmgcalc" and where it's number falls in the range of values.  To be honest, I have absolutely no idea how I would do this with pure html or sheetworkers, especially considering that I still know so little about how sheet workers operate and I can't find any examples similar to what I'm doing here. Any help would be greatly appreciated and I can't thank you enough for your help thus far!
1673482394

Edited 1673488577
GiGs
Pro
Sheet Author
API Scripter
A sheet worker would be the best way to do this. There is a RQ Glorantha seet on the github already that probably does it. But if you need to create it yourself (remember to put it inside a script block): on ( 'change:strength change:size' , function () {         getAttrs ([ 'strength' , 'size' ], function ( values ) {             let str = + values . strength || 0 ;             let siz = + values . siz e || 0 ;             let damage = str + siz ;             let dice = '-1d6' ;             if ( damage > 32 ) {                 dice = '+' + Math . ceil (( damage - 24 )/ 16 ) + 'd6' ;             } else if ( damage > 24 ) {                 dice = '+1d4' ;             } else if ( damage > 16 ) {                 dice = 'none' ;             } else if ( damage > 12 ) {                 dice = '-1d4' ;             }             setAttrs ({                 damage_display : dice             });         });     }); Also, I'd recommend changing this line                 dice = 'none'; to                 dice = '+0'; That way you can use the damage_display value in damage rolls directly. A text value would cause it to fail.