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

Simple Sheet Worker Question

Hi Forum, I am completely new to this stuff, and I've been struggling with making a minor change with a custom sheet that already exists. So here's the thing: on("change:magic_02_name", function() { getAttrs(["magic_02_name"], function(values) { if(values.magic_02_name == "Whatever Magic Spell"){ setAttrs({magic_02_effect: "It will destroy the enemies"});      });     }); }); </script> Both attributes "magic_02_name" and "magic_02_effect" are text boxes. I want to let the sheet automatically show a built-in text content ("It will destroy the enemies" in this example) in the textbox "magic_02_effect" whenever player puts the magic spell name in the textbox "magic_02_name" ("Whatever Magic Spell" in the example). The script simply doesn't work. Any help would be appreciated.
1619661161
Finderski
Pro
Sheet Author
Compendium Curator
Is this the only sheet worker on the character sheet? Because it looks like you have one too many }); for one.   Does the developer console say anything, because if there's more than one worker and one of the others has a problem, it could cause sheet workers to not trigger at all.
Finderski said: Is this the only sheet worker on the character sheet? Because it looks like you have one too many }); for one.   Does the developer console say anything, because if there's more than one worker and one of the others has a problem, it could cause sheet workers to not trigger at all. Thank you for pointing that out. As you said, other workers were not working with the script. I fixed it to this version, and now the other workers do work. However the new script is still not working. on("change:magic_02_name", function() { getAttrs(["magic_02_name"], function(values) { if(values.magic_02_name == "Spell Name"){ setAttrs({magic_02_effect:"Description"}); } }); });
1619701271
Finderski
Pro
Sheet Author
Compendium Curator
Is this a field from within a repeating section? I ask, because I created a short character sheet and the sheet worker worked fine.  Here's my code: Name: <input type="text" name="attr_magic_02_name" /> Effect: <input type="text" name="attr_magic_02_effect" /> <script type="text/worker"> on("change:magic_02_name", function() { getAttrs(["magic_02_name"], function(values) { let effectText = ""; if(values.magic_02_name == "Spell Name"){ effectText = "Description"; } setAttrs({magic_02_effect:effectText}); }); }); </script> The only difference I made to the script was to place the description in a variable and move the setAttrs outside of the if statement (you want to call  setAttrs as few times as possible, so assuming this script may grow beyond a single field and if, I moved it). So, given that, there's either another part of your sheet workers that interfering, or this is in a repeating section, in which case, the worker itself needs to be done a little differently, because the change and getAttrs stuff would need to be different.  For example: on("change: repeating_magic: magic_02_name", function() { getAttrs([" repeating_magic_ magic_02_name"], function(values) { let effectText = ""; if(values. repeating_magic_ magic_02_name == "Spell Name"){ effectText = "Description"; } setAttrs({magic_02_effect:effectText}); }); }); That assumes the repeating section is called magic.