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

Change a dropdown using a sheet worker

1487773408
Matthew C
Pro
Sheet Author
I have the following problem. I have a dropdown change based on the weapon type. Using css I have it the drop down change when a different weapon is chosen and this works perfectly. However when I change the weapon, the drop down changes (this is good) but the choice of the old one remains (Which includes the changes to the character sheet) until you take a new choice (because they are all the same attribute name) What I want is to use a sheet worker to "Reset" the choice back to NONE (which is not used, so this resets it all). <script type="text/worker"> on("change:m1_1", function() { getAttrs(["m1_1"], function(values) { var attrs = {None1_Class1:0,B1_Class1:0,Shi11_Cla (Very very very long code) if (_.has(attrs, values.class1)) { attrs[values.class1] = 1; } setAttrs(attrs); }); }); </script> (The above is the type of code I use to change the values and this works perfectly) What I need is something like this: <script type="text/worker"> on("change:class1", function() { getAttrs(["m1_1"], function(values) { setAttrs({ None1_Class1) }); }); }); </script> Incase you need it for reference, this is ONE of the m1_1 dropdowns <select style="width: 165px;font-size:94%" name="attr_m1_1"> <option value="None_Class1" selected>None</option> <option value="Ala1_Class1">Alarm</option> <option value="AV1_Class1">Anti-Vehicle</option> <option value="Bea1_Class1">Beartrap</option> <option value="IR11_Class1">Increased Radius 1</option> <option value="IR21_Class1">Increased Radius 2</option> <option value="TP1_Class1">Trigger: Proximity</option> <option value="TR1_Class1">Trigger: Remote</option> <option value="TT1_Class1">Trigger: Tripwire</option> </select> Any kind of help with this would be freaking awesome :D
1487776868

Edited 1487777178
chris b.
Pro
Sheet Author
API Scripter
you mean this? you don't need to do getAttrs for this: Basic easy way is just what you need. //assuming class1 is the 1st weapon dropdown //basic easy way: on("change:class1", function() { setAttrs({m1_1:'NoneClass1'}); }); I added a few options in the "advanced way" just for informational purposes you can use it or not, or just learn when you need to use it: i added a check for eventInfo.sourceType. you may not need it on the class1 dropdown, but you will need it on any eventhandler watching the m1_1 dropdown. when setting m1_1 back to the default, you can hardcode the default, or you can use '' which will tell Riley's code to set it to the default no matter what it is. I usually use '' so my javascript doesn't have to know what the default is in the html. //advanced way, check the type, use '' etc: on("change:class1", function(eventInfo) { if (eventInfo.sourceType==='player'||eventInfo.sourceType==='api'){ setAttrs({m1_1:''}); //using '' tells Roll20 to reset to default } }); //if you have any type of on:change watching the m1_1 dropdown, you will want to be sure to not fire it the code above updates it //you do this by checking eventInfo.sourceType for 'sheetworker' //because in the above case you probably don't want it to do anything. Unless you do, then don't check the type on("change:m1_1", function(eventInfo) { if (eventInfo.sourceType!=='sheetworker'){ //do stuff } });
1487778890
Matthew C
Pro
Sheet Author
Thanks mate, you are awesome. I will look into the more advanced one later, but for now the simple one did exactly what I needed :D