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

Sheetworkers, used to work, now not working?

1569013396
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
So, been testing the sheet and its been working fine, then I had my first session last night and it was *kinda* working, it was triggering and changing attributes *some* of the time. And seemingly stopped updating attributes towards the end of the session.I just pulled up my sheet and its not triggering at all.&nbsp; Its a World of Darkness style system, you select a Skill and an Attribute and use the roller button in the top right to roll. In the below example, I've selected Close Combat and Cunning.&nbsp; The sheet worker below should trigger when a rollSkill or rollAttribute changes on the sheet. Transferring the appropriate attribute's value to active_Skill or active_Attribute. I even added a console log to see if its triggering and I'm not seeing it in my console.&nbsp; Here's just the sheet workers... I figure if I put a new typo somewhere, one of the functions should still trigger but the roller is rolling 0+0 &lt;!---------Sheet Workers ---------------&gt; &lt;script type="text/worker"&gt; const skills = ['Academics', 'Athletics', 'CloseCombat', 'Culture', 'Empathy', 'Firearms', 'Integrity', 'Leadership', 'Medicine', 'Occult', 'Persuasion', 'Pilot', 'Science', 'Subterfuge', 'Survival', 'Technology']; on(`change:${skills.join(' change:')} change:rollskill sheet:opened`, function() { console.log(Script Worker, setting Skill); getAttrs([...skills, 'rollSkill'],function(values) { const skill_name = values.rollSkill; const skill_value = values[skill_name]; setAttrs({ active_skill: skill_value }); }); }); const attributes = ['Intellect', 'Cunning', 'Resolve', 'Might', 'Dexterity', 'Stamina', 'Presence', 'Manipulation', 'Composure']; on(`change:${attributes.join(' change:')} change:rollattr sheet:opened`, function() { console.log(Script Worker, setting Attribute); getAttrs([...attributes, 'rollAttr'],function(values) { const attr_name = values.rollAttr; const attr_value = values[attr_name]; setAttrs({ active_attribute: attr_value }); }); }); &lt;/script&gt; Full HTML here if you need to test it.&nbsp; <a href="https://pastebin.com/WuwyVftS" rel="nofollow">https://pastebin.com/WuwyVftS</a> Full CSS <a href="https://pastebin.com/ay0KrRFy" rel="nofollow">https://pastebin.com/ay0KrRFy</a>
1569017214
GiGs
Pro
Sheet Author
API Scripter
Your console log statements will be breaking the workers as they are now. Replace with console.log("Script Worker setting " + Skill);
1569017790
GiGs
Pro
Sheet Author
API Scripter
Change these &lt;input type="hidden" name="attr_active_attribute" value="0"&gt; &lt;input type="hidden" name="attr_active_skill" value="0"&gt; from hidden to visible, during testing &lt;input type="number" name="attr_active_attribute" value="0"&gt; &lt;input type="number" name="attr_active_skill" value="0"&gt; And change your workers to set them to a default value that will show if there's an error const skills = ['Academics', 'Athletics', 'CloseCombat', 'Culture', 'Empathy', 'Firearms', 'Integrity', 'Leadership', 'Medicine', 'Occult', 'Persuasion', 'Pilot', 'Science', 'Subterfuge', 'Survival', 'Technology']; on(`change:${skills.join(' change:')} change:rollskill sheet:opened`, function() { console.log("Script Worker setting " + Skill); getAttrs([...skills, 'rollSkill'],function(values) { const skill_name = values.rollSkill; const skill_value = values[skill_name] || -9; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(`Script Worker setting ${Skill}- Name: ${skill_name}; Value: ${skill_value}`) setAttrs({ active_skill: skill_value }); }); }); I set a default value of -9 there so you can immediately see there's something wrong with it. Then go through every attribute and every skill, and see if one shows an incorrect value. I'd think the most likely culprit is you have incorrect data in one of the sheet's attribute/skill values, or you have a misnamed attribute or skill in the html.
1569020884
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Throwing a lot of Skill not defined in the console log, which I suppose is a good sign that its at least triggering?&nbsp;
1569034554
GiGs
Pro
Sheet Author
API Scripter
oh yeah, that first console statement is invalid and should be removed. There is no "Skill" variable.
1569034699

Edited 1569038187
GiGs
Pro
Sheet Author
API Scripter
Use this instead const skills = ['Academics', 'Athletics', 'CloseCombat', 'Culture', 'Empathy', 'Firearms', 'Integrity', 'Leadership', 'Medicine', 'Occult', 'Persuasion', 'Pilot', 'Science', 'Subterfuge', 'Survival', 'Technology']; on(`change:${skills.join(' change:')} change:rollskill sheet:opened`, function() { console.log("Script Worker setting Skill"); getAttrs([...skills, 'rollSkill'],function(values) { const skill_name = values.rollSkill; const skill_value = values[skill_name]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(`Name: ${skill_name}; Value: ${skill_value}`); setAttrs({ active_skill: skill_value || -9 }); }); }); Edit: &nbsp;Actually since you're error checking, use this version instead. You'll be able to see if skill_name and skill_value are properly defined from the console.log
1569040291

Edited 1569042352
GiGs
Pro
Sheet Author
API Scripter
Aha, I'll bet the issue is the uppercase letters in skills and attributes. the change line only accepts lower case letters. If you have attributes named with an upper case letter, it will sometimes work, but often won't. That might explain the erraticness you're seeing.&nbsp; Change this line on(`change:${skills.join(' change:')} change:rollskill sheet:opened`, function() { to the following, to make sure everything is converted to lower case on this line only. on(`${skills.map(item =&gt; `change:${item.toLowerCase()} `).join(' ')} change:rollskill sheet:opened`, function() { Edit: &nbsp;my first version of this post had an error. Its fixed now (crosses fingers). Likewise for the attributes on(`${attributes.map(item =&gt; `change:${item.toLowerCase()} `).join(' ')} change:rollattr sheet:opened`, function() {
1570234365

Edited 1570234397
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Hey GiGs! Sorry it took awhile for me to test and respond, the game was canceled and been busy. I didn't look like the new lines with the lower-casing was working for me but futzed with previous block and got it working (for now, ehehe). Here's where I'm at for future generations.&nbsp; const skills = ['Academics', 'Athletics', 'CloseCombat', 'Culture', 'Empathy', 'Firearms', 'Integrity', 'Leadership', 'Medicine', 'Occult', 'Persuasion', 'Pilot', 'Science', 'Subterfuge', 'Survival', 'Technology']; on(`change:${skills.join(' change:')} change:rollskill sheet:opened`, function() { &nbsp; &nbsp; console.log("----------SCRIPT WORKER SETTINGS CONSOLE"); &nbsp; &nbsp; getAttrs([...skills, 'rollSkill'],function(values) {&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const skill_name = values.rollSkill;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const skill_value = values[skill_name]; &nbsp; &nbsp; &nbsp; &nbsp; console.log(`-------SKILL TEST--------Name: ${skill_name}; Value: ${skill_value}`); &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({ active_skill: skill_value || -9 });&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; }); }); const attributes = ['Intellect', 'Cunning', 'Resolve', 'Might', 'Dexterity', 'Stamina', 'Presence', 'Manipulation', 'Composure']; on(`change:${attributes.join(' change:')} change:rollattr sheet:opened`, function() { &nbsp; &nbsp; getAttrs([...attributes, 'rollAttr'],function(values) {&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const attr_name = values.rollAttr;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const attr_value = values[attr_name]; &nbsp; &nbsp; &nbsp; &nbsp; console.log(`-------ATTRIBUTE TEST--------Name: ${attr_name}; Value: ${attr_value}`); &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({ active_attribute: attr_value || -9 });&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; }); });
1570259699

Edited 1570259867
GiGs
Pro
Sheet Author
API Scripter
I'm glad it's working :) I do suggest changing the on(change) lines as I recommended in my last post. Mixed case words can and frequently do cause issues with change events, and they are supposed to be all lower case (yes, even when the attribute itself is not lower case). In case it's confusing, the map part of that statement, this bit: skills.map(item =&gt; `change:${item.toLowerCase()} `) is basically a compact for(i) loop - it just loops through the existing skills array, and transforms each item in the array (changing, say, " Academics " to " change:academics "), giving you a new array with the transformed elements. Then the join at the end turns that new array into a string, the same way join does in the original version.