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

Problem with Multiple Script Tags

So I put together the current incarnation of the 4e L5R sheet. Some time back, another author went in and edited the code to take out all the script tags I had separating the various sheet workers and place all the sheet workers inside a single open and close set of script tags. This broke the insight calculation code we worked so hard to get right here about a year back. I thought I had it working, but I guess I didn't. And then when I tried to push an update I added a typo and broke all the sheet workers, so I need to push a new update pronto, but I can't get that bugged fixed. Here's what happens. If I put open and closed script tags just around the insight calculation code, and I put a second set of open and closed script tags around all the other sheet workers, it works fine, but I understand from the notes of that other author, that isn't allowed anymore for some reason (not sure why, there was an update or something, I'm not in the loop on that.) But as soon as I take out that close tag and open in the middle so all the code is inside one set of tags all the insight code breaks. The other sheet workers, such as the one that calculate the stats the insight code uses, seem to work fine. Just not that insight code. I'll post the code in question below. Ideas? <script type="text/worker"> // Insight Calculation Worker          on("sheet:opened change:Insight", function() { getAttrs(["foo_insight"], function(values) { setAttrs({ foo_rank: Math.max(1,Math.round((values.foo_insight - 112) / 25)) }); }); }); var elements = ['foo_air', 'foo_earth', 'foo_fire', 'foo_water', 'foo_void'], ranks = ['rank_acting', 'rank_artisan', 'rank_calligraphy', 'rank_courtier', 'rank_divination', 'rank_etiquette', 'rank_games', 'rank_investigation', 'rank_lore', 'rank_Lore2', 'rank_Lore3', 'rank_Medicine', 'rank_Meditation', 'rank_Perform', 'rank_Sincerity', 'rank_Spellcraft', 'rank_Tea_Ceremony', 'rank_rhigh', 'rank_Athletics', 'rank_Battle', 'rank_Defense', 'rank_Horsemanship', 'rank_Hunting', 'rank_Iaijutsu', 'rank_Jiujutsu', 'rank_Chain_Weapons', 'rank_Heavy_Weapons', 'rank_Kenjutsu', 'rank_Knives', 'rank_Kyujutsu', 'rank_Ninjutsu', 'rank_Polearms', 'rank_Spears', 'rank_Staves', 'rank_WarFan', 'rank_AnimalHandling', 'rank_Commerce', 'rank_Craft', 'rank_Engineering', 'rank_Sailing', 'rank_Forgery', 'rank_Intimidation', 'rank_SleightofHand', 'rank_Stealth', 'rank_Temptation', 'BCourtier', 'BEtiquette', 'add_insight'], eventString = [...elements, ...ranks].map(s => `change:${s}`).join(' ') + ' change:repeating_rehigh:rank_rehigh remove:repeating_rehigh' + ' change:repeating_rweap:rank_rweap remove:repeating_rweap' + ' change:repeating_rcraft:rank_rcraft remove:repeating_rcraft' + ' change:repeating_rlow:rank_rlow remove:repeating_rlow'; // This function does the actual calculation and attribute-setting after we have all the names var calcFooInsight = function (repeatingNames) { getAttrs([...elements, ...ranks, ...repeatingNames], function (values) { let sum = elements.reduce((s, k) => (s + (parseInt(values[k]) * 10 || 0)), 0) + ranks.reduce((s, k) => (s + (parseInt(values[k]) || 0)), 0) + repeatingNames.reduce((s, k) => (s + (parseFloat(values[k]) || 0)), 0); setAttrs({ foo_insight: Math.round(sum) }); }); }; // Collect necessary data for calculation on(eventString, function () { getSectionIDs('repeating_rehigh', function (idArrayRehigh) { getSectionIDs('repeating_rweap', function (idArrayRweap) { getSectionIDs('repeating_rcraft', function (idArrayRcraft) {     getSectionIDs('repeating_rlow', function (idArrayRlow) {         let attrNamesRehigh = idArrayRehigh.map(id => "repeating_rehigh_" + id + "_rank_rehigh"),         attrNamesRweap = idArrayRweap.map(id => "repeating_rweap_" + id + "_rank_rweap"),             attrNamesRcraft = idArrayRcraft.map(id => "repeating_rcraft_" + id + "_rank_rcraft"),                 attrNamesRlow = idArrayRlow.map(id => "repeating_rlow_" + id + "_rank_rlow");                 calcFooInsight([...attrNamesRehigh, ...attrNamesRweap, ...attrNamesRcraft, ...attrNamesRlow]);                                 });                             });         });         }); }); </script>
1545571447
GiGs
Pro
Sheet Author
API Scripter
I might be the one who combined them all into one script tag. I changed a bunch, that might be one of them. There was a very good reason: after a roll20 update, only sheet workers in the first script tag actually worked. All others were ignored. This lasted for quite a while and people posted on the forum asking for a fix. But that bug has since been fixed, so you can have multiple script tags again.  That said, it doesnt make sense to me that your script only works in its own script tag. As far as the sheet is concerned, it should make no difference at all if its in its own script tag, or in the script tag shared by other scripts.  Is it possible there's another issue - an improper closure perhaps - that has escaped discovery?
I've gone through in notepad++ and haven't been able to find one. I thought of that too. I also ran it through the compiler they showed me then I first started this, figuring it would show me. No joy so far. I was hoping fresh eyes might have an idea.
I'm glad to hear that bug is fixed. :)
1545614972
GiGs
Pro
Sheet Author
API Scripter
I wonder if there's an error in a different script, the one just before this one when they are in the same script section.  I did notice you have a lot of upper case letters in the change: statements ,  and I wonder if the error still occurs if you use toLowerCase() to fix them? Change statements are always supposed to be lower case. That wouldnt explain why it works sometimes and not others though.
You can try moving the code to an earlier section within the <script> section to see if the error shifts to another bit of code.
This is the earliest bit of script. I had the same thought, though, so I moved the ring sheet workers, (that do the ability scores) BEFORE this (I tried that before posting). It had no effect.