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

my sheetworker script doesn't seem to be firing

I'm creating a character sheet for the sci-fi horror game Mothership and having problems getting any sheet worker scripts to cooperate. I've stripped everything out but one example, because I think I can figure the rest out if I can get this one working. When you create a character, you choose one of 4 loadouts. I'm trying to include a dropdown of the 4 loadouts, and then have a text field next to it populate with the relevant items whenever you choose your loadout. However, the script doesn't seem to change the value no matter what I do. Below is my current code. I've tried a few different things in the script not using getAttrs and using the values returned by the onchange function formatting the functions "normally" (function(){  }) using a series of if/else instead of that big ternary, etc but nothing seems to make the value change. using a span instead of an input for loadoutequipment using a span as well as an input setting a default value for loadoutequipment (new sheets when I do this will have the default value in place but it will never change) Could someone help guide me on what's going wrong here? Thanks a ton. <div class="sheet-main">     <span>LOADOUT</span>     <select name="attr_loadout" title="Choose Loadout">             <option value="excavation">excavation</option>             <option value="exploration">exploration</option>             <option value="extermination">extermination</option>             <option value="examination">examination</option>      </select>             <input type="text" name="attr_loadoutequipment"> </div> <script type="text/worker">     on("change:loadout", () => { getAttrs(['loadoutequipment','loadout'], v => { const newValues = { "loadoutequipment" : String(v.loadout) === 'excavation' ? 'Crowbar, Hand Welder, Laser Cutter, Body Cam, Bioscanner, Infrared Goggles, Lockpick Set, Vaccsuit (Oxygen Tank, Mag-Boots, Short-range Comms)' : String(v.loadout) === 'exploration' ? 'Vibechete, Rigging Gun, Flare Gun, First Aid Kit, Vaccsuit (Long-range Comms, Oxygen Tank), Survey Kit, Water Filter, Locator, Rebreather, Binoculars, Flashlight, Camping Gear, MREs x7' : String(v.loadout) === 'extermination' ? '"SMG, Frag Grenade x6, Standard Battle Dress (Heads-up Display, Body Cam, Short-range Comms), Stimpak x6, Electronic Tool Kit' : String(v.loadout) === 'examination' ? 'Scalpel, Tranq Pistol, Stun Baton, Hazard Suit, Medscanner, Automed x6, Pain Pills x6, Stimpak x6, Cybernetic Diagnostic Scanner' : 'error' }; log newValues; setAttrs(newValues); });     } </script>
1536614945

Edited 1536615685
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You're missing a closing parentheses on the on("change..., and you're fat arrow syntax isn't quite correct : <div class="sheet-main">     <span>LOADOUT</span>     <select name="attr_loadout" title="Choose Loadout">             <option value="excavation">excavation</option>             <option value="exploration">exploration</option>             <option value="extermination">extermination</option>             <option value="examination">examination</option>      </select>             <input type="text" name="attr_loadoutequipment"> </div> <script type="text/worker">     on("change:loadout", () => { getAttrs(['loadoutequipment','loadout'], ( v ) => { //You need to have the variable that you're going to use in parentheses const newValues = { "loadoutequipment" : String(v.loadout) === 'excavation' ? 'Crowbar, Hand Welder, Laser Cutter, Body Cam, Bioscanner, Infrared Goggles, Lockpick Set, Vaccsuit (Oxygen Tank, Mag-Boots, Short-range Comms)' : String(v.loadout) === 'exploration' ? 'Vibechete, Rigging Gun, Flare Gun, First Aid Kit, Vaccsuit (Long-range Comms, Oxygen Tank), Survey Kit, Water Filter, Locator, Rebreather, Binoculars, Flashlight, Camping Gear, MREs x7' : String(v.loadout) === 'extermination' ? '"SMG, Frag Grenade x6, Standard Battle Dress (Heads-up Display, Body Cam, Short-range Comms), Stimpak x6, Electronic Tool Kit' : String(v.loadout) === 'examination' ? 'Scalpel, Tranq Pistol, Stun Baton, Hazard Suit, Medscanner, Automed x6, Pain Pills x6, Stimpak x6, Cybernetic Diagnostic Scanner' : 'error' }; log ( newValues ) ; //and Log is a function, so you need to pass what you're logging to the function setAttrs(newValues); });     } );//This needs to have a closing parentheses and an ending semicolon. </script> You probably would have seen a syntax error in the console log when loading into your game. I also recommend the google closure compiler to look for little typos like this. EDITS: Missed one other thing above; I've added it to the code annotation above. I'd also look at doing your assignment of loadoutequipment a little different as your current method is not very readable:     <script type="text/worker"> on("change:loadout", () => { getAttrs(['loadoutequipment','loadout'], (v) => { const loadoutSwitch = {                     excavation:'Crowbar, Hand Welder, Laser Cutter, Body Cam, Bioscanner, Infrared Goggles, Lockpick Set, Vaccsuit (Oxygen Tank, Mag-Boots, Short-range Comms)',                      exploration:'Vibechete, Rigging Gun, Flare Gun, First Aid Kit, Vaccsuit (Long-range Comms, Oxygen Tank), Survey Kit, Water Filter, Locator, Rebreather, Binoculars, Flashlight, Camping Gear, MREs x7',                      extermination:'SMG, Frag Grenade x6, Standard Battle Dress (Heads-up Display, Body Cam, Short-range Comms), Stimpak x6, Electronic Tool Kit',                      examination:'Scalpel, Tranq Pistol, Stun Baton, Hazard Suit, Medscanner, Automed x6, Pain Pills x6, Stimpak x6, Cybernetic Diagnostic Scanner'                     },                     newValues = {};                 newValues.loadoutequipment = loadoutSwitch[v.loadout] : ''; log(`newValues: ${JSON.stringify(newValues)}`); //I'd also recommend stringifying your object to log it so that it's easier to read in the console log. setAttrs(newValues);         }); }); </script>
Thank you Scott. I can't believe I was missing a parentheses there, I appreciate your help.