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

Old Sheet Worker Stopped Working

All right. I swear this sheet worker used to work. I can't see anything that's changed, and characters I've pulled up had the proper values calculated using it, then when I changed a value, it broke and returned a bad value. So something is broken. I've decided to stop worrying about the timeline and just try to fix it. The problem is the values of the "elements" variables, foo_air, foo_earth, etc, which should be added in at 10 x their value. They aren't being added in at all. If I change them it does seem to trigger the worker. They seem to be correct in the variables in the sheet. They just aren't being calculated in the actual equation where they are meant to be added together, multiplied by ten, and then added to the ranks and all the repeating cells. The total value returned is JUST the total of the normal ranks and the repeating cells. Anyway, here's the code, as we created way back when. Tell me if you can help me spot the issue. <!-- Insight Calculation Worker --> <script type="text/worker"> 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> I think it has to be this section, but I'm still weak on this sheet worker thing: 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) }); }); So I'm willing to accept that there might be something else I'm not seeing. Any ideas?
1531437262
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
So, the API and character sheet sandboxes are much more closely linked now. The ... operator is valid in sheets, but not in the API. This could be causing a crash maybe?
1531437638
Jakob
Sheet Author
API Scripter
Scott C. said: So, the API and character sheet sandboxes are much more closely linked now. The ... operator is valid in sheets, but not in the API. This could be causing a crash maybe? Spread syntax (for arrays) actually works fine in the API.
1531437848
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hmm, wonder if they fixed it. It used to crash the API.
Anyone have any idea with this? I'm still stuck. :)
1532368145
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Can you post the relevant HTML code as well?
Sure. The Insight/XP section looks like this: &lt;tr&gt; &lt;td&gt;&lt;div&gt;&lt;label class="short" style=display:inline&gt;&lt;span data-i18n="total-experience-u"&gt;Total Experience&lt;/span&gt;&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" value='0' name="attr_Total_Experience" /&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div&gt;&lt;label style=display:inline&gt;&lt;span data-i18n="courtier-bonus-u"&gt;Courtier Bonus&lt;/span&gt;&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;select style="width:110px;" name="attr_bcourtier" class="sheet-skillselect"&gt; &lt;option value="0" data-i18n="0-to-insight-u"&gt;0 to Insight&lt;/option&gt; &lt;option value="3" data-i18n="+3-to-insight-u"&gt;+3 to Insight&lt;/option&gt; &lt;option value="10" data-i18n="+10-to-insight-u"&gt;+10 to Insight&lt;/option&gt; &lt;/select&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;div&gt;&lt;label class="short" style=display:inline&gt;&lt;span data-i18n="available-experience-u"&gt;Available Experience&lt;/span&gt;&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" value='40' name="attr_Experience" /&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div&gt;&lt;label style=display:inline&gt;&lt;span data-i18n="etiquette-bonus-u"&gt;Etiquette Bonus&lt;/span&gt;&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;select style="width:110px;" name="attr_betiquette" class="sheet-skillselect"&gt; &lt;option value="0" data-i18n="0-to-insight-u"&gt;0 to Insight&lt;/option&gt; &lt;option value="3" data-i18n="+3-to-insight-u"&gt;+3 to Insight&lt;/option&gt; &lt;option value="10" data-i18n="+10-to-insight-u"&gt;+10 to Insight&lt;/option&gt; &lt;/select&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;input type="hidden" name="attr_foo_insight" value="100" /&gt; &lt;td&gt;&lt;div&gt;&lt;label class="short" style=display:inline&gt;&lt;span data-i18n="insight-u"&gt;Insight&lt;/span&gt;&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" disabled="true" name="attr_Insight" value="@{foo_insight}" &lt;/td&gt; &lt;td&gt;&lt;div&gt;&lt;label style=display:inline&gt;&lt;span data-i18n="additional-ranks-u"&gt;Additional Ranks&lt;/span&gt;&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" name="attr_add_insight" value="0" /&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; The Attribute section looks like this: &lt;div class="center"&gt; &lt;div class="sheet-6colrow"&gt; &lt;div class="sheet-col" style=background-color:#B4C8DB;&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="attribute"&gt; &lt;img width="64%" src="<a href="http://i.imgur.com/qkte4EC.png&quot;/" rel="nofollow">http://i.imgur.com/qkte4EC.png"/</a>&gt; &lt;h3 data-i18n="air-u" class="attribute"&gt;Air&lt;/h3&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;input type="hidden" name="attr_foo_air" value="2" /&gt; &lt;input type="number" value="@{foo_air}" disabled="true" name="attr_Air"/&gt; &lt;button type='roll' name='roll_Air' value='/em @{name} rolls Air! \n\n/roll [[@{Air}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;p&gt;&lt;/label class="traits"&gt;&lt;span data-i18n="reflexes-u"&gt;Reflexes&lt;/span&gt;&lt;/p&gt; &lt;input type="number" value='2' name="attr_Reflexes" /&gt; &lt;button type='roll' name='roll_Reflexes' value='/em @{name} rolls Reflexes! \n\n/roll [[@{Reflexes}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;p&gt;&lt;/label&gt;&lt;span data-i18n="awareness-u"&gt;Awareness&lt;/span&gt;&lt;/p&gt; &lt;input type="number" value='2' name="attr_Awareness" /&gt; &lt;button type='roll' name='roll_Awareness' value='/em @{name} rolls Awareness! \n\n/roll [[@{Awareness}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class="sheet-col" style=background-color:#B39C85;&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="attribute"&gt; &lt;img width="67%" src="<a href="http://i.imgur.com/bHoZ2zK.png&quot;/" rel="nofollow">http://i.imgur.com/bHoZ2zK.png"/</a>&gt; &lt;h3 data-i18n="earth-u" class="attribute"&gt;Earth&lt;/h3&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;input type="hidden" name="attr_foo_earth" value="2" /&gt; &lt;input type="number" value="@{foo_earth}" disabled="true" name="attr_Earth"/&gt; &lt;button type='roll' name='roll_Earth' value='/em @{name} rolls Earth! \n\n/roll [[@{Earth}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;p&gt;&lt;/ladel&gt;&lt;span data-i18n="stamina-u"&gt;Stamina&lt;/span&gt;&lt;/p&gt; &lt;input type="number" value='2' name="attr_Stamina" /&gt; &lt;button type='roll' name='roll_Stamina' value='/em @{name} rolls Stamina! \n\n/roll [[@{Stamina}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;p&gt;&lt;/ladel&gt;&lt;span data-i18n="willpower-u"&gt;Willpower&lt;/span&gt;&lt;/p&gt; &lt;input type="number" value='2' name="attr_Willpower" /&gt; &lt;button type='roll' name='roll_Willpower' value='/em @{name} rolls Willpower! \n\n/roll [[@{Willpower}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class="sheet-col" style=background-color:#EBA93C;&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="attribute"&gt; &lt;img width="62%" src="<a href="http://i.imgur.com/7hVQbK7.png&quot;/" rel="nofollow">http://i.imgur.com/7hVQbK7.png"/</a>&gt; &lt;h3 data-i18n="fire-u" class="attribute"&gt;Fire&lt;/h3&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;input type="hidden" name="attr_foo_fire" value="2" /&gt; &lt;input type="number" value="@{foo_fire}" disabled="true" name="attr_Fire"/&gt; &lt;button type='roll' name='roll_Fire' value='/em @{name} rolls Fire! \n\n/roll [[@{Fire}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;p&gt;&lt;/ladel&gt;&lt;span data-i18n="agility-u"&gt;Agility&lt;/span&gt;&lt;/p&gt; &lt;input type="number" value='2' name="attr_Agility" /&gt; &lt;button type='roll' name='roll_Agility' value='/em @{name} rolls Agility! \n\n/roll [[@{Agility}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;p&gt;&lt;/ladel&gt;&lt;span data-i18n="intelligence-u"&gt;Intelligence&lt;/span&gt;&lt;/p&gt; &lt;input type="number" value='2' name="attr_Intelligence" /&gt; &lt;button type='roll' name='roll_Intelligence' value='/em @{name} rolls Intelligence! \n\n/roll [[@{Intelligence}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class="sheet-col" style=background-color:#98ADDA;&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="attribute"&gt; &lt;img width="66%" src="<a href="http://i.imgur.com/sOvpnaa.png&quot;/" rel="nofollow">http://i.imgur.com/sOvpnaa.png"/</a>&gt; &lt;h3 data-i18n="water-u" class="attribute"&gt;Water&lt;/h3&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;input type="hidden" name="attr_foo_water" value="2" /&gt; &lt;input type="number" value="@{foo_water}" disabled="true" name="attr_water"/&gt; &lt;button type='roll' name='roll_water' value='/em @{name} rolls Water! \n\n/roll [[@{Water}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;p&gt;&lt;/ladel&gt;&lt;span data-i18n="strength-u"&gt;Strength&lt;/span&gt;&lt;/p&gt; &lt;input type="number" value='2' name="attr_Strength" /&gt; &lt;button type='roll' name='roll_Strength' value='/em @{name} rolls Strength! \n\n/roll [[@{Strength}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;p&gt;&lt;/ladel&gt;&lt;span data-i18n="perception-u"&gt;Perception&lt;/span&gt;&lt;/p&gt; &lt;input type="number" value='2' name="attr_Perception" /&gt; &lt;button type='roll' name='roll_Perception' value='/em @{name} rolls Perception! \n\n/roll [[@{Perception}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class="sheet-col" style=background-color:#BDA7A8;&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="attribute"&gt; &lt;img width="65%" src="<a href="http://i.imgur.com/jnlStIs.png&quot;/" rel="nofollow">http://i.imgur.com/jnlStIs.png"/</a>&gt; &lt;h3 data-i18n="void-u" class="attribute"&gt;Void&lt;/h3&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;input type="number" value='2' name="attr_foo_void" /&gt; &lt;button type='roll' name='roll_Void' value='/em @{name} rolls Void! \n\n/roll [[@{foo_void}]]d10!!'&gt;&lt;/button&gt;&lt;br/&gt; &lt;/div&gt; &lt;div class="attribute"&gt; &lt;p&gt;&lt;/ladel&gt;&lt;span data-i18n="void-spent-u" &gt;Void Spent&lt;/span&gt;&lt;/p&gt; &lt;input type="number" value='0' name="attr_void_spent" /&gt; &lt;/div&gt; &lt;div class="sheet-col"&gt; &lt;div class="attribute"&gt; &lt;p&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;
There are simple sheet workers that set the rings when you change the attributes. Those are working fine and the rings are set with their proper values.