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

Providing a text result from a table based on a numeric value

I'm currently trying to add a functionality to a custom character sheetbased on the sum of two attributes (strength and toughness). This sum provides a total allowed carry weight for the character, this isn't mathematical but is based on a table, values below: <option value="0">0.9kg</option> <option value="1">2.25kg</option> <option value="2">4.5kg</option> <option value="3">9kg</option> <option value="4">18kg</option> <option value="5">27kg</option> <option value="6">36kg</option> <option value="7">45kg</option> <option value="8">56kg</option> <option value="9">67kg</option> <option value="10">78kg</option> <option value="11">90kg</option> <option value="12">112kg</option> <option value="13">225kg</option> <option value="14">337kg</option> <option value="15">450kg</option> <option value="16">675kg</option> <option value="17">900kg</option> <option value="18">1,350kg</option> <option value="19">1,800kg</option> <option value="20">2,250kg</option> What I was trying for is a sheet item that, for example, if the sum of strength and toughness is 7 it would Display "45kg". Is this possible without an API? Thanks!
1483400368
Finderski
Pro
Sheet Author
Compendium Curator
Yes...the easiest way I could think of would be a  Sheetworker . You might be able to do it purely with CSS, but it would be complicated—probably something like hidden calculated field to get the value, and then a span whose content is controlled by the value of the hidden field.
1483417401
Lithl
Pro
Sheet Author
API Scripter
You could probably get a good enough approximation of this from an autocalc field, but a sheet worker would be much  simpler. For example, see the Exalted 2e feat of strength section, which was created before sheet workers existed (although this could be updated to replace the various @{FOSIndex-N} attributes with @{FOSIndex}**N): <input type="hidden" disabled="true" name="attr_FOSIndex" value="(@{Strength}+@{Athletics}*(1-@{Athletics|max}))" /> <input type="hidden" disabled="true" name="attr_FOSIndex-2" value="(@{FOSIndex} * @{FOSIndex})" /> <input type="hidden" disabled="true" name="attr_FOSIndex-3" value="(@{FOSIndex-2} * @{FOSIndex})" /> <input type="hidden" disabled="true" name="attr_FOSIndex-4" value="(@{FOSIndex-2} * @{FOSIndex-2})" /> <input type="hidden" disabled="true" name="attr_FOSIndex-5" value="(@{FOSIndex-3} * @{FOSIndex-2})" /> <input type="hidden" disabled="true" name="attr_FOSIndex-6" value="(@{FOSIndex-3} * @{FOSIndex-3})" /> <input type="hidden" disabled="true" name="attr_FOSIndex-7" value="(@{FOSIndex-4} * @{FOSIndex-3})" /> <input type="hidden" disabled="true" name="attr_FOSIndex-8" value="(@{FOSIndex-4} * @{FOSIndex-4})" /> <input type="hidden" disabled="true" name="attr_FOSIndex-9" value="(@{FOSIndex-5} * @{FOSIndex-4})" /> <div class="right">Lift/Pull/Push: <input type="number" name="attr_FeatOfStrengthLift" style="width: 4em" title="Lift weight in pounds" value="round((19 * @{FOSIndex-9})/9072-(205 * @{FOSIndex-8})/2016+(3187 * @{FOSIndex-7})/1512-(1171 * @{FOSIndex-6})/48+(74761 * @{FOSIndex-5})/432-(74525 * @{FOSIndex-4})/96+(9916159 * @{FOSIndex-3})/4536-(1856837 * @{FOSIndex-2})/504+(214435 * @{FOSIndex})/63-1200)" disabled="true" /></div> <input type="hidden" disabled="true" name="attr_FOSIndex2" value="(((@{FOSIndex} - 5) + abs(@{FOSIndex} - 5)) / 2)" /> <input type="hidden" disabled="true" name="attr_FOSIndex2-2" value="(@{FOSIndex2} * @{FOSIndex2})" /> <input type="hidden" disabled="true" name="attr_FOSIndex2-3" value="(@{FOSIndex2-2} * @{FOSIndex2})" /> <input type="hidden" disabled="true" name="attr_FOSIndex2-4" value="(@{FOSIndex2-2} * @{FOSIndex2-2})" /> <div class="right">Throw Object: <input type="number" name="attr_FeatOfStrengthThrow" title="Throw weight in pounds for (Strength + Athletics) yards" value="-5 * @{FOSIndex2-4} / 12 + 25 * @{FOSIndex2-3} / 6 - 115 * @{FOSIndex2-2} / 12 + 515 * @{FOSIndex2} / 6" disabled="true" /></div> In a slightly easier-to-read fashion: Lift, Pull, Push = round( (19 * X^9) / 9072 - (205 * X^8) / 2016 + (3187 * X^7) / 1512 - (1171 * X^6) / 48 + (74761 * X^5) / 432 - (74525 * X^4) / 96 + (9916159 * X^3) / 4536 - (1856837 * X^2) / 504 + (214435 * X) / 63 - 1200 ) where X = Strength + Athletics Throw = -5 * Y^4 / 12 + 25 * Y^3 / 6 - 115 * Y^2 / 12 + 515 * Y / 6 where Y = max(X - 5, 0) This crazy function brought to you by  polynomial interpolation . The equivalent function for your table would be something along the lines of: - 0.0000536317 x^16 + 0.00173728 x^15 - 0.0430452 x^14 + 0.834371 x^13 - 12.833 x^12 + 157.923 x^11 - 1560.8 x^10 + 12387.2 x^9 - 78632.3 x^8 + 396055 x^7 - 1562640 x^6 + 4738000 x^5 - 10732900 x^4 + 17407600 x^3 - 18876900 x^2 + 12081700 x - 3383270 Or, with a sheet worker script, you could get something nice and simple, like an actual table lookup: var table = [ 0.9, 2.25, 4.5, 9, 18, 27, // etc. ]; on('change:table-lookup', function() { getAttrs(['table-lookup'], function(values) { setAttrs({ weight: table[parseInt(values['table-lookup'])] + 'kg' }); }); });
Hi Brian,  I'm trying to get my head around this so if you could help I'll be really grateful. I'm working on the sheet worker script and trying to include the following: +@{MutT}+floor(@{Toughness}/10)+@{MutS}+floor(@{Strength}/10) In my character example this provides a result of 7 which should automatically bring up 45kg How do I include this on the sheet worker script? Thanks!
1483490490
Lithl
Pro
Sheet Author
API Scripter
You'll have to either hard-code the equation into the sheet worker (get MutT, Toughness, MutS, and Strength, use Math.floor(), etc.), or else parse the equation coming from the attribute.