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 .
×

Sheet Worker Help Request - setting the correct select option values

User selects if they are Int or Wis base caster in a select box to determine which modifier to use for some math down in sheet worker I can't quite figure out what values to set them as to be able to pull those int-mod / wis-mod attributes down without it just be the value of the text and not the value of the attribute. Any ideas on best practices to perform this? HTML: <td class="sheet-table-header3" style="width: 20%; border: 1px solid black;"><span data-i18n="casting-ability">Casting Ability</span>:<br> <select class="sheet-table-data-center" style="height: 24px; width: 64px;" name="attr_spellcastingstat" title="spellcastingstat"> <option type="text" style="width: 45px;" value="int-mod" data-i18n="intelligence-a" selected>Int</option> <option type="text" style="width: 45px;" value="wis-mod" data-i18n="wisdom-a">Wis</option> </select> </td> Sheet worker: on("sheet:opened change:manamod change:spellcastingstat change:wis-base change:int-base change:wis-misc change:int-misc change:wis-temp change:int-temp change:casterlevel", function() { getAttrs(["spellcastingstat", "manamod", "casterlevel"], function(values) { setAttrs({ mana_max: (((parseInt(values["spellcastingstat"],10) * 2) * parseInt(values["casterlevel"],10)) + parseInt(values["manamod"],10)) }); }); });
1610874642

Edited 1610874753
GiGs
Pro
Sheet Author
API Scripter
When creating a selct option, its not the same as input, you dont set type="text"  (type is always text, as it happens), so it should probably be <option style="width: 45px;" value="int-mod" data-i18n="intelligence-a" selected>Int</option> setting inline styles is discouraged, its better to set classes. I'm not sure how well setting a width there will work - selects are notoriously fiddly to style, and tryin g to style the options differently from the containing select might not work (I think it works most reliably when just changing things like colour). Anyway, on to your question: Your select is set up okay, but you need to make sure the getAttrs in your sheet worker gets those values too. Here's one way to do it (with some notes after): on('sheet:opened change:manamod change:spellcastingstat change:wis-mod change:int-mod change:casterlevel', function() {     getAttrs(['spellcastingstat', 'manamod', 'casterlevel', 'wis-mod', 'int-mod'], function(values) {         const whichmod = values.spellcastingstat;         const stat_mod = parseInt(values[whichmod]) || 0;         const level = parseInt(values.casterlevel) || 0;         const mana_mod = parseInt(values.manamod) || 0;         const mana_max = stat_mod * 2 + level + mana_mod;         setAttrs({             mana_max: mana_max         });     }); }); I changed your change line to respond to int-mod and wis-mod, instead of the base attaributes. They'll need to be calculated by a sheet worker, and cant be autocalc attributes. This avoids the need to calculate the modifiers again within this worker. So you need to grab which mod to use from the select, and then use that to grab the actual modifier. The rest should be straightforward, but I've broken it down into steps to make it clearer.
you dont set type="text" True! setting inline styles is discouraged True! Minor style adjustments inline =/ no issues and then use that to grab the actual modifier. parseInt(values[whichmod]) I never looked at java before today so trying to pick it up on the fly. That was the thing i was missing! I was going down the path of an IF statement, this is much cleaner. I now notice all the issues autocalc creates and I am trying push everything into the work sheet. Very much appreciate the assist!
1610877979
GiGs
Pro
Sheet Author
API Scripter
You're welcome! Minor point: I never looked at  java  before today  This is an understandable confusion, but  java  and  javascript  are different languages. sheet workers use javascript.