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

Sheetworker for option elements

Hello! I am trying to figure out how to get a sheetworker to set certain values based on one of two options picked in with the option element. Here is what I am currently working with <select name="attr_aptype">                 <option value="martialhybrid">Martial/Hybrid</option>                 <option value="caster" >Caster</option>             </select> The idea is that when the pick an option the resource used will be determined by the number assigned to the option multiplied by level plus any modifiers used with it.  Any and all advice is greatly appreciated!
1668533787

Edited 1668533878
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hi Kaeden, You'll need to set a listener for changes to your aptype  attribute as well as your level  attribute that will then set the value of your output attribute. This would look something like this (I'm using calc_ap  as the output attribute for demonstration purposes; replace with your actual attribute as needed): <select name="attr_ap_type"><!-- Note, I changed this to snake_case. Snake_ or kebab-case are the best naming formats for attributes/buttons as they are easy to read when in a macro, and do not rely on capitalization which is not as usable when writing sheetworkers. --> <option value="martialhybrid">Martial/Hybrid</option> <option value="caster">Caster</option> </select> <input type="number" value="" name="attr_level"> <input type="number" readonly name="attr_calc_ap"> <script type="text/javascript"> const apValues = {//Random ap values for the types. Replace with values appropriate to your actual system. martialhybrid:1, caster:2 }; on('change:ap_type change:level',(event)=>{ getAttrs(['ap_type','level'],(attributes) => { const setObj = {}; //I use an object to accumulate my changes for any given sheetworker operation as it makes debugging easier and I can then dynamically add attributes to it as needed for an operation. setObj.calc_ap = (+attributes.level || 0) * apValues[attributes.ap_type]; setAttrs(setObj,{silent:true});//I nearly always use silent:true on setAttrs to prevent unanticpated event cascades. }) }) </script>