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

Sheet Worker Click button to run script help

I have been digging for a while on this one. I can not find an issue with my sheet worker script. I used one from Kryx that i found on the fourm and adjusted it to fit what i needed. I am sure it is some small issue but after 2 hours I can not find it. I what to click a button that will then run the script to reduce armor by 1 if the max armor is above 0. if it is 0 then i want it to check the next armor and repeat. It is for a home brew rule set for armor in cyberpunk that we use.  Here is the button: <button type="action" name="act_hit" class="txt-btn">HIT</button> This is the armor in the sheet: <h3>ARMOR:</h3>     <input type="checkbox" name="attr_ar1e" value="1"/>     ARMOR: <input name="attr_a1" type="text" style="width: 150px;"/>     TYPE: <input name="attr_a1type" type="text" style="width: 50px;" value="UNDER"/><br/>     RATING: <input type="number" name="attr_ar1" value="0" /> / <input type="number" name="attr_ar1_max" value="0"/>     ENCUMBRANCE: <input type="number" name="attr_a1enc" value="0" />     <hr>     <input type="checkbox" name="attr_ar2e" value="1"/>     ARMOR: <input name="attr_a2" type="text" style="width: 150px;" />     TYPE: <input name="attr_a2type" type="text" style="width: 50px;" value="ARMOR"/><br/>     RATING: <input type="number" name="attr_ar2" value="0" /> / <input type="number" name="attr_ar2_max" value="0"/>     ENCUMBRANCE: <input type="number" name="attr_a2enc" value="0" />     <hr>     <input type="checkbox" name="attr_ar3e" value="1"/>     ARMOR: <input name="attr_a3" type="text" style="width: 150px;" />     TYPE: <input name="attr_a3type" type="text" style="width: 50px;" value="SHEILD"/><br/>     RATING: <input type="number" name="attr_ar3" value="0" /> / <input type="number" name="attr_ar3_max" value="0"/>     ENCUMBRANCE: <input type="number" name="attr_a3enc" value="0" /> This is the sheet worker: <script type="text/worker"> on("clicked:hit", function(){     getAttrs(["ar1_max", "ar2_max", "ar3_max"], function(values){         var ar1_max = parseInt(values.ar1_max);         var ar2_max = parseInt(values.ar2_max);         var ar3_max = parseInt(values.ar3_max);         if (ar3_max > 0) {         setAttrs({"ar3_max": (ar3_max - 1) });         } else if {(ar2_max > 0) {         setAttrs({"ar2_max": (ar2_max - 1) });         } else if {(ar1_max > 0) {         setAttrs({"ar1_max": (ar1_max - 1) });         }     }); }); Any help would be great. I am just stuck. Thank you,
1597995826
GiGs
Pro
Sheet Author
API Scripter
Both of your else if statements have an { that shouldn't be there. if (ar3_max > 0) {         setAttrs({"ar3_max": (ar3_max - 1) }); } else if (ar2_max > 0) {         setAttrs({"ar2_max": (ar2_max - 1) }); } else if (ar1_max > 0) {         setAttrs({"ar1_max": (ar1_max - 1) }); } I'd also add that it's good practice to get in the habit of using just one setAttrs statement. It doesnt matter here, but it might if you ever expanded this worker. You could do that like this: on("clicked:hit", function(){     getAttrs(["ar1_max", "ar2_max", "ar3_max"], function(values){         var ar1_max = parseInt(values.ar1_max);         var ar2_max = parseInt(values.ar2_max);         var ar3_max = parseInt(values.ar3_max);         var output = {};         if (ar3_max > 0) {             output.ar3_max = (ar3_max - 1);         } else if (ar2_max > 0) {             output.ar2_max = (ar2_max - 1);         } else if (ar1_max > 0) {             output.ar1_max = (ar1_max - 1);         }         setAttrs(output);     }); });
It works! No more scrap paper and tons of notes for me during games just to keep up with armor. Thank you so much. This formula is going to help me alot. I think i can see the layout of how it reads the code better. You are the best.
The hardest part because I am so new to css and java is finding where to put commas or other symbols. I have read and watched tutorials to learn what I have. You have helped me a few times now and I appreciate it. I dont mind doing the work or research, sometimes I just get stuck. Few more lines of code and the sheet will be 100%
1598028228
Andreas J.
Forum Champion
Sheet Author
Translator
Adam S. said: The hardest part because I am so new to css and java Java Script . I've never touched Java, but I know it's a completely unrelated thing to what we are working with... :D
Haha good one. Java keeps me up at night.
1598037493
GiGs
Pro
Sheet Author
API Scripter
Adam S. said: It works! No more scrap paper and tons of notes for me during games just to keep up with armor. Thank you so much. This formula is going to help me alot. I think i can see the layout of how it reads the code better. You are the best. It's always nice to hear things like that!