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

Script Worker Trouble

1593717377

Edited 1593719774
Eli N.
Pro
Compendium Curator
Having a little bit of trouble with this script worker. It's not outputting the modified ranges. They are still 0 on("change:repeating_rangedweapons:target_size change:repeating_rangedweapons:0_range change:repeating_rangedweapons:four_range change:repeating_rangedweapons:six_range change:repeating_rangedweapons:adv_sighting change:repeating_rangedweapons:eight_range sheet:opened", function() {         getAttrs(["repeating_rangedweapons_target_size","repeating_rangedweapons_adv_sighting","repeating_rangedweapons_eight_range","repeating_rangedweapons_six_range","repeating_rangedweapons_0_range","repeating_rangedweapons_four_range"], function(values) {             const adv_sighting = int(values.repeating_rangedweapons_adv_sighting);             const target_size = int(values.repeating_rangedweapons_target_size);             const 0_range = int(values.repeating_rangedweapons_0_range);             const four_range = int(values.repeating_rangedweapons_four_range);             const six_range = int(values.repeating_rangedweapons_six_range);             const eight_range = int(values.repeating_rangedweapons_eight_range);             0_range_adjusted= Math.min(0_range*target_size*(adv_sighting+1),eight_range);             four_range_adjusted= Math.min(four_range*target_size*(adv_sighting+1),eight_range);             six_range_adjusted= Math.min(six_range*target_size*(adv_sighting+1),eight_range);             eight_range_adjusted= Math.min(eight_range*target_size*(adv_sighting+1),eight_range);         setAttrs({             repeating_rangedweapons_0_range_adjusted: 0_range_adjusted,             repeating_rangedweapons_four_range_adjusted: four_range_adjusted,             repeating_rangedweapons_six_range_adjusted: six_range_adjusted,             repeating_rangedweapons_eight_range_adjusted: eight_range_adjusted         });     }); }); Here are those attributes. (there is space between these with other stuff in between them)    <fieldset class="repeating_rangedweapons">             <div class="sheet-col-1-16"><input type="checkbox" name="attr_adv_sighting" value=".5" /></div>             <div class="sheet-col-1-16" title="Range at which you roll a d20"><input type="text" name="attr_0_range"/></div>               <div class="sheet-col-1-16 sheet-vert-bottom"><input type="text" name="attr_0_range_adjusted" value="0" /></div>             <div class="sheet-col-1-16" title="Range at which you roll a d20-4"><input type="text" name="attr_four_range"/></div>             <div class="sheet-col-1-16 sheet-vert-bottom"><input type="text" name="attr_four_range_adjusted" value="0" /></div>             <div class="sheet-col-1-16" title="Range at which you roll a d20-6"><input type="text" name="attr_six_range"/></div>             <div class="sheet-col-1-16 sheet-vert-bottom"><input type="text" name="attr_six_range_adjusted" value="0" /></div>             <div class="sheet-col-1-16" title="Range at which you roll a d20-8"><input type="text" name="attr_eight_range"/></div>             <div class="sheet-col-1-16 sheet-vert-bottom"><input type="text" name="attr_eight_range_adjusted" value="0"  /></div>
1593724124
GiGs
Pro
Sheet Author
API Scripter
There's a big problem with these two variables: const 0_range = int(values.repeating_rangedweapons_0_range); 0_range_adjusted= Math.min(0_range*target_size*(adv_sighting+1),eight_range); Variable names cant start with a number, in javascript. Change those to zero_range should fix things. The last four variables (with _adjusted in the name) aren't properly declared (no conts, let, or var at the start), but that's not a breaking fault. 
1593807906
Eli N.
Pro
Compendium Curator
So I changed the 0's to zero and added let, and I am still getting diddly squat on("change:repeating_rangedweapons:target_size change:repeating_rangedweapons:zero_range change:repeating_rangedweapons:four_range change:repeating_rangedweapons:six_range change:repeating_rangedweapons:adv_sighting change:repeating_rangedweapons:eight_range sheet:opened", function() {         getAttrs(["repeating_rangedweapons_target_size","repeating_rangedweapons_adv_sighting","repeating_rangedweapons_eight_range","repeating_rangedweapons_six_range","repeating_rangedweapons_zero_range","repeating_rangedweapons_four_range"], function(values) {             const adv_sighting = int(values.repeating_rangedweapons_adv_sighting);             const target_size = int(values.repeating_rangedweapons_target_size);             const zero_range = int(values.repeating_rangedweapons_zero_range);             const four_range = int(values.repeating_rangedweapons_four_range);             const six_range = int(values.repeating_rangedweapons_six_range);             const eight_range = int(values.repeating_rangedweapons_eight_range);             let zero_range_adjusted= Math.min(zero_range*target_size*(adv_sighting+1),eight_range);             let four_range_adjusted= Math.min(four_range*target_size*(adv_sighting+1),eight_range);             let six_range_adjusted= Math.min(six_range*target_size*(adv_sighting+1),eight_range);             let eight_range_adjusted= Math.min(eight_range*target_size*(adv_sighting+1),eight_range);         setAttrs({             repeating_rangedweapons_zero_range_adjusted: zero_range_adjusted,             repeating_rangedweapons_four_range_adjusted: four_range_adjusted,             repeating_rangedweapons_six_range_adjusted: six_range_adjusted,             repeating_rangedweapons_eight_range_adjusted: eight_range_adjusted         });     }); });
1593810175

Edited 1593810224
GiGs
Pro
Sheet Author
API Scripter
Quick check - did you change the 0_range attribute name in the fieldset too? Also, eight_range is being set to a value above zero? The sheet worker above should work, so the problem is elsewhere. Can you post the full html and css in pastebin or gist.github.com, and I'll give it a quick check. (The new sheet sandbox makes this so convenient!)
1593812284
Eli N.
Pro
Compendium Curator
Yeah, I changed it else where as well.  Yeah so each ranged weapon has a max range (eight_range), while size modifiers or talents (advanced sighting) can treat targets as closer or farther away, the max range is still the max range. 
1593812504
Eli N.
Pro
Compendium Curator
Here is the Github link&nbsp; <a href="https://github.com/generalripphook/roll20hackmaster" rel="nofollow">https://github.com/generalripphook/roll20hackmaster</a> While you are looking at it, you are the one that helped me with the code for the incrementing wound tracker (wound 1, wound 2....etc.) it is currently only saying wound 1 on repeat.&nbsp;
1593815786
GiGs
Pro
Sheet Author
API Scripter
The sheet worker is working for me, though it does have one error. const&nbsp;target_size&nbsp;=&nbsp;int(values.repeating_rangedweapons_target_size); This line is getting the integer value of size. But for Small and Tiny sizes, the value is 0.66 and 0.5 respectively, so that always returns 0. If you put the size at Medium or higher, and make sure the other values have an entry in them, you should get proper values. You have this earlier in the script block: const&nbsp;int&nbsp;=&nbsp;score&nbsp;=&gt;&nbsp;parseInt(score)&nbsp;||&nbsp;0; create a similar function for floats: const&nbsp;float =&nbsp;score&nbsp;=&gt;&nbsp;parseFloat(score)&nbsp;||&nbsp;0; then you can change the above line to const&nbsp;target_size&nbsp;=&nbsp;float(values.repeating_rangedweapons_target_size); By the way, you should put both the const int and const float functions right at the start of your script block, to ensure they can be used in any following workers.
1593815815

Edited 1593816257
GiGs
Pro
Sheet Author
API Scripter
Remind me whats the code for the incrementing wound tracker? Also, can you link the previous thread we discussed it, so i can get up to speed more easily.
1593816062
GiGs
Pro
Sheet Author
API Scripter
Also, forgot to mention: for sheet workers like this repeating_rangedweapons worker, you should not have sheet:opened &nbsp;oon the changed line. It doesnt stop the worker working, but it cannot run on sheet opened. repeating section workers using syntax like this: getAttrs(["repeating_rangedweapons_target_size","repeating_rangedweapons_adv_sighting", etc... can only run when a change occurs inside a repeating section. No row id exists, and so roll20 gets the row id from the changing attribute. But when the sheet opens, no change is occurring, and so roll20 cant supply a row id, and so the sheet worker crashes and you get errors in the browser console.&nbsp; It still works when you change things later, but its better to remove the sheet:opened &nbsp;from such workers to avoid the unneccessary errors.
1593818455

Edited 1594075375
GiGs
Pro
Sheet Author
API Scripter
I also couldnt help noticing that last sheet worker from lines 239-499, you have a long chain of getAttrs/setAttrs, that all trigger of the same attribute change. That is very&nbsp; &nbsp;bad practice. You should combine the code inside all those getAttrs blocks into one getAttrs block. Instead of doing this, for instance: getAttrs(["skill_dice_switch"], function(values) { var check = parseInt(values.skill_dice_switch) || 0; var diceAM = check ? "[[1d100+@{skill_animal_mimicry}]] vs Opposing Roll" : "[[d100]] Skill: [[@{skill_animal_mimicry}]]"; setAttrs({ animal_mimicry_dice: diceAM }); }); getAttrs(["skill_dice_switch"], function(values) { var check = parseInt(values.skill_dice_switch) || 0; var diceAH = check ? "[[1d100+@{skill_animal_husbandry}]] vs Opposing Roll" : "[[d100]] Skill: [[@{skill_animal_husbandry}]]"; setAttrs({ animal_husbandry_dice: diceAH }); }); getAttrs(["skill_dice_switch"], function(values) { var check = parseInt(values.skill_dice_switch) || 0; var diceB = check ? "[[1d100+@{skill_boating}]] vs Opposing Roll" : "[[d100]] Skill: [[@{skill_boating}]]"; setAttrs({ boating_dice: diceB }); }); you should do this, which is much more efficient: getAttrs(["skill_dice_switch"], function(values) { var check = parseInt(values.skill_dice_switch) || 0; var diceAM = check ? "[[1d100+@{skill_animal_mimicry}]] vs Opposing Roll" : "[[d100]] Skill: [[@{skill_animal_mimicry}]]"; var diceAH = check ? "[[1d100+@{skill_animal_husbandry}]] vs Opposing Roll" : "[[d100]] Skill: [[@{skill_animal_husbandry}]]"; var diceB = check ? "[[1d100+@{skill_boating}]] vs Opposing Roll" : "[[d100]] Skill: [[@{skill_boating}]]"; setAttrs({ animal_mimicry_dice: diceAM, animal_husbandry_dice: diceAH, boating_dice: diceB }); }); To save you the work, here's a sheet worker that does it all, using a loop. If you find it more understandable, you can use the previous manual method. on("change:skill_dice_switch&nbsp;sheet:opened",&nbsp;function()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;getSectionIDs('repeating_skill',&nbsp;function(idarray)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getAttrs(["skill_dice_switch"],&nbsp;function(values)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;skills&nbsp;=&nbsp;['acting',&nbsp;'animal_mimicry',&nbsp;'animal_husbandry',&nbsp;'boating',&nbsp;'cartography',&nbsp;'climbing',&nbsp;'current_affairs',&nbsp;'distraction','diplomacy','disguise',&nbsp;'escape_artist',&nbsp;'fire_building',&nbsp;'glean_information','hiding',&nbsp;'interrogation',&nbsp;'intimidation',&nbsp;'jumping',&nbsp;'law',&nbsp;'listening',&nbsp;'observation',&nbsp;'oration',&nbsp;'persuasion',&nbsp;'pick_pocket',&nbsp;'reading_lips',&nbsp;'recruiting',&nbsp;'resist_persuasion',&nbsp;'rope_use',&nbsp;'salesmanship',&nbsp;'scrutiny',&nbsp;'seduction',&nbsp;'sneaking',&nbsp;'survival',&nbsp;'skilled_liar',&nbsp;'torture',&nbsp;'tracking',]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;create&nbsp;a&nbsp;variable&nbsp;to&nbsp;hold&nbsp;the&nbsp;attribute&nbsp;names&nbsp;and&nbsp;their&nbsp;value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;output&nbsp;=&nbsp;{}; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;check&nbsp;=&nbsp;parseInt(values.skill_dice_switch)&nbsp;||&nbsp;0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;diceRS&nbsp;=&nbsp;check&nbsp;?&nbsp;"[[1d100+@{mastery}]]&nbsp;vs&nbsp;Opposing&nbsp;Roll"&nbsp;:&nbsp;"[[d100]]&nbsp;Skill:&nbsp;[[@{mastery}]]"; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;now&nbsp;loop&nbsp;through&nbsp;every&nbsp;row&nbsp;id,&nbsp;and&nbsp;update&nbsp;the&nbsp;skillname_dice&nbsp;attribute&nbsp;on&nbsp;that&nbsp;row &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;idarray.forEach(id&nbsp;=&gt;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output[`repeating_skill_${id}_skillname_dice`]&nbsp;=&nbsp;diceRS; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;build&nbsp;the&nbsp;strings&nbsp;&nbsp;for&nbsp;non-repeating&nbsp;skills &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;skills.forEach(skill&nbsp;=&gt;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output[`${skill}_dice`]&nbsp;=&nbsp;check&nbsp;?&nbsp;`[[1d100+@{skill_${skill}}]]&nbsp;vs&nbsp;Opposing&nbsp;Roll`&nbsp;:&nbsp;`[[d100]]&nbsp;Skill:&nbsp;[[@{skill_${skill}}]]`; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;update&nbsp;the&nbsp;stats&nbsp;on&nbsp;the&nbsp;sheet &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setAttrs(output); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;});&nbsp;&nbsp;&nbsp;&nbsp; });
1593976625
Eli N.
Pro
Compendium Curator
Yeah, I am baffled by this, it's still not working for me. Really good to know about the sheet: opened.&nbsp; I assumed that was bad practice, I just had never gone back to edit it. I'll make those changes to that long section.&nbsp;
1593978749
GiGs
Pro
Sheet Author
API Scripter
I dont know what to tell you. I copied your code and made just one change (changed the int to float for size) and it worked perfectly. If its not working, I suggest creating a new campaign, copying your code in and testing on a new character. Make sure you set non-zero values for each of the range bands, and a decent size for the size drop down.
1594065513

Edited 1594096747
Eli N.
Pro
Compendium Curator
I just wasn't adjusting anything, so therefore not causing the sheet worker to activate. I see my issue.&nbsp; This is the thread for the wounds thing.&nbsp; <a href="https://app.roll20.net/forum/post/8779579/repeating-section-question/?pageforid=8779579#post-8779579" rel="nofollow">https://app.roll20.net/forum/post/8779579/repeating-section-question/?pageforid=8779579#post-8779579</a>
1594083624
GiGs
Pro
Sheet Author
API Scripter
Whats the issue with wounds? I havent made any changes to the sheet. I entered a max HP value. Then created some wounds, and they updated the hp accurately. Is the problem somewhere else?
i don't understand&nbsp;
1594096780
Eli N.
Pro
Compendium Curator
The issue is that it calls every wound, "wound 1" and not "wound 1", "wound 2"....
1594099963
GiGs
Pro
Sheet Author
API Scripter
Oh yes, I never noticed that. The problem is in my initial code. This line in CSS .charsheet&nbsp;.sheet-reset&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;counter-reset:&nbsp;wound-counter; } should be .charsheet&nbsp;.sheet-wound-reset&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;counter-reset:&nbsp;wound-counter; } This was not easy to spot, lol.
1594265002
Eli N.
Pro
Compendium Curator
I would never have gotten that. Thanks so much!&nbsp;
1594265490
GiGs
Pro
Sheet Author
API Scripter
You're welcome. It took me way too long to spot it too, lol. Those kinds of errors are the trickiest :)