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

[HELP] Sheet Worker problem

1592397125
Finderski
Pro
Sheet Author
Compendium Curator
I have a sheet worker to build a list of skills (skills can be renamed and that's why I use a sheet worker to "build" the names) in a repeating section.  The problem,  TypeError: t is undefined (in Firefox) or  Uncaught TypeError: Cannot read property 'toString' of undefined (in Chrome), only occurs the first time the sheet worker is triggered. Subsequent times, no issue. The issue occurs at the same spot every time (it builds the list properly until it hits the  spell casting skill). I have a drop down in this repeating section that controls the button to either roll the relevant skill for the spell/power, roll damage only for the spell/power, or roll both the skill and the damage. The default is Damage only. If I change that drop down to Skill Only, or Atk+Damage, the skill list displays, but Spellcasting and Weird Science are blank (i.e. no label to know what I'm picking). If I then select the other option (Atk+Damage or Skill Only, whichever I didn't choose the first time), the sheet worker triggers with no exception and the skill list is fully populated. I can then swap back and forth between the two with no issues. This same stuff is used for the Weapons repeating section and has no issues at all. It is always Spellcasting where it dies. Any help in identifying why this is happening would be appreciated. Here's the relevant code snippets: HTML+Sheet Worker : <!--Athletics--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="athletics">Athletics</label> = <input type="text" class="sheet-csnInput" name="attr_athleticsname" value="" /></div> <!--Faith--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="faith">Faith</label> = <input type="text" class="sheet-csnInput" name="attr_faithname" value="" /></div> <!--Focus--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="focus">Focus</label> = <input type="text" class="sheet-csnInput" name="attr_focusname" value="" /></div> <!--Performance--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="performance">Performance</label> = <input type="text" class="sheet-csnInput" name="attr_performancename" value="" /></div> <!--Psionics--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="psionics">Psionics</label> = <input type="text" class="sheet-csnInput" name="attr_psionicsname" value="" /></div> <!--Spellcasting--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="spellcasting">Spellcasting</label> = <input type="text" class="sheet-csnInput" name="attr_spellcastingname" value="" /></div> <!--Weird Science--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="weird-science">Weird Science</label> = <input type="text" class="sheet-csnInput" name="attr_weirdsciencename" value="" /></div> <fieldset class='repeating_spells'> <label class="sheet-configlabels" data-i18n="button-behavior">Button Behavior</label> <select name="attr_spellbutton" title="@{repeating_spells_$#_spellbutton}" class="sheet-spellbutton"> <option value="2" data-i18n="skill-only">Skill Only</option> <option value="0" data-i18n="attack-and-damage-abbr">Atk + Dmg</option> <option value="1" data-i18n="damage-only" selected>Damage Only</option> </select> <input class="sheet-spellbutton" type="hidden" name="attr_spellbutton" value="1" /> <div class='sheet-spellskill'> <label class="sheet-configlabels" data-i18n="skill">Skill</label> <div class="sheet-container"> <div class="sheet-child"> <label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-athletics" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="athletics" /><span name='attr_sathleticsname'></span></label> <label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-faith" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="faith" checked /><span name='attr_sfaithname'></span></label> <label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-focus" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="focus" /><span name='attr_sfocusname'></span></label> <label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-performance" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="performance" /><span name='attr_sperformancename'></span></label> <label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-psionics" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="psionics" /><span name='attr_spsionicsname'></span></label> <label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-spellcasting" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="spellcasting" /><span name='attr_sspellcastingname'></span></label> <label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-weirdscience" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="weirdscience" /><span name='attr_sweirdsciencename'></span></label> <label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-unskilled" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="unskilled" /><span data-i18n='unskilled'>Unskilled</span></label> <input type="hidden" class="sheet-select-radio sheet-" name="attr_spellskill" value="faith" /> <div class="sheet-athletics"><span name='attr_sathleticsname'></span></div> <div class="sheet-faith"><span name='attr_sfaithname'></span></div> <div class="sheet-focus"><span name='attr_sfocusname'></span></div> <div class="sheet-performance"><span name='attr_sperformancename'></span></div> <div class="sheet-psionics"><span name='attr_spsionicsname'></span></div> <div class="sheet-spellcasting"><span name='attr_sspellcastingname'></span></div> <div class="sheet-weirdscience"><span name='attr_sweirdsciencename'></span></div> <div class="sheet-unskilled"><span data-i18n='unskilled'>Unskilled</span></div> </div> </div> </div> </fieldset> <script type="text/worker"> const spellskillnamelist = ["faithname","athleticsname","focusname","performancename","psionicsname","ritualname","spellcastingname","weirdsciencename"]; // similarly could consider a refactor on("change:repeating_spells:spellbutton change:repeating_weapons:weaponbutton", function(eventInfo) { console.log("iii sourceAttribute: " + eventInfo.sourceAttribute + " iii"); let parts = eventInfo.sourceAttribute.split('_'); let field, value; if (parts[1] === "weapons") { field = weaponsskillnamelist; } else { field = spellskillnamelist; } if (eventInfo.newValue === "2" || eventInfo.newValue === "0") { console.log("Make sure the drop down is populated with skill names"); setSkillDropdown(parts[1], field, "get names", parts[2]); } else { console.log("No need to update anything..."); } }); spellskilllist.forEach(spellskilllist => { on(`change:${spellskilllist}name`, function(eventInfo) { log("Spell Skill List","Skill Name Change","lime"); console.log("Triggering Attribute: " + eventInfo.sourceAttribute); let field = "s" + eventInfo.sourceAttribute; let value = eventInfo.newValue; setSkillDropdown("spells", field, value); }); }); function setSkillDropdown(section, field, value, rowid) { let repsection = `repeating_${section}`; let setskill = {}; if(Array.isArray(field) && value === "get names") { //is Array console.log("Field array: " + field); repsection += `_${rowid}_`; console.log("!!! Passed an Array !!!"); getAttrs(field, function(v) { let setfield; let fieldprefix; let setvalue; if (section === "weapons") {fieldprefix = "r";} else {fieldprefix = "s";} for (let a = 0; a < field.length; a++) { console.log("iii section ID: " + rowid + " iii"); setfield = repsection + fieldprefix + field[a]; setvalue = v[field[a]]; console.log(`iii setfield: ${setfield} iii`); console.log(`iii setvalue: ${setvalue} iii`); setskill[setfield] = setvalue; } /*let defaultval = field[0].split('name'); if (section === "weapons") { setfield = repsection + "weaponskill"; } else { setfield = repsection + "spellskill"; } setskill[setfield] = defaultval;*/ console.log("Setting: " + JSON.stringify(setskill)); setAttrs(setskill); }); } else { console.log("iii passed a single field, so need to update that single field iii"); getSectionIDs(repsection, function(idArray) { //passing in a single field for (let i = 0; i < idArray.length; i++) { console.log(`${repsection}_${idArray[i]}_${field}: ${value}`); setskill[`${repsection}_${idArray[i]}_${field}`] = value; } setAttrs(setskill); }); } } </script> CSS : .sheet-spellbutton { width: 100px; -webkit-appearance: none; -moz-appearance: none; appearance: none; } .sheet-spellskill { display: none; } .sheet-spellbutton[value="0"] + .sheet-spellskill, .sheet-spellbutton[value="2"] + .sheet-spellskill { display: inline-block; margin-left: 10px; } .sheet-container { width: 100px; border-bottom: 1px solid black; } .sheet-container, .sheet-child { display: inline-block; } .sheet-child { vertical-align: middle; width: 100px; height: 28px; } .sheet-child label { display: none; z-index: 1; } .sheet-ddmenu { font-weight: normal; font-size: 1em; width: 95%; } .sheet-child:hover { border-radius: 10px; background: silver; position:absolute; width: 100px; margin-top: -14px; height: auto; z-index: 1; padding: 5px; } .sheet-child:hover label { display: inline-block; margin-left: -5px; } div.sheet-athletics, div.sheet-unskilled, div.sheet-faith, div.sheet-focus, div.sheet-performance, div.sheet-psionics, div.sheet-spellcasting, div.sheet-weirdscience { width: 100px; height: 28px; line-height:28px; color: black; border-bottom: 1px solid black; text-align: center; display: none; } .sheet-child:not(:hover) input.sheet-select-radio[value="athletics"] ~ div.sheet-athletics, .sheet-child:not(:hover) input.sheet-select-radio[value="unskilled"] ~ div.sheet-unskilled, .sheet-child:not(:hover) input.sheet-select-radio[value="faith"] ~ div.sheet-faith, .sheet-child:not(:hover) input.sheet-select-radio[value="focus"] ~ div.sheet-focus, .sheet-child:not(:hover) input.sheet-select-radio[value="performance"] ~ div.sheet-performance, .sheet-child:not(:hover) input.sheet-select-radio[value="psionics"] ~ div.sheet-psionics, .sheet-child:not(:hover) input.sheet-select-radio[value="spellcasting"] ~ div.sheet-spellcasting, .sheet-child:not(:hover) input.sheet-select-radio[value="weirdscience"] ~ div.sheet-weirdscience { display: block; } label.sheet-ddmenu:hover { background-color: orange; } .sheet-child:hover > label.sheet-ddmenu > .sheet-select-radio:checked + span { font-weight: bold; font-size: 1em; } Here's the output to the console of the object being passed into the setAttrs function: Setting: {"repeating_spells_-ma1clcdjg30hftolte9_sfaithname":"Faith","repeating_spells_-ma1clcdjg30hftolte9_sathleticsname":"Athletics","repeating_spells_-ma1clcdjg30hftolte9_sfocusname":"Focus","repeating_spells_-ma1clcdjg30hftolte9_sperformancename":"Performance","repeating_spells_-ma1clcdjg30hftolte9_spsionicsname":"Psionics", "repeating_spells_-ma1clcdjg30hftolte9_sspellcastingname":"Spellcasting","repeating_spells_-ma1clcdjg30hftolte9_sweirdsciencename":"Weird Science" } The bolded/Italicized bit is where it dies...everything before that is set properly on the sheet.
1592410777

Edited 1592410901
Andreas J.
Forum Champion
Sheet Author
Translator
The problem,  TypeError: t is undefined (in Firefox) or  Uncaught TypeError: Cannot read property 'toString' of undefined (in Chrome), only occurs the first time the sheet worker is triggered. Subsequent times, no issue. It sounds like the order in which you have some stuff defined or set means that some of the values are called before they are defined by the first time, and on the second time they are triggered, they are defined from the previous trigger. When I ran the JS in a closure complier , it didn't give any errors or warnings.
1592412990
Finderski
Pro
Sheet Author
Compendium Curator
The weird thing is that object above is what is passed to the setAttrs function.  And it's the same issue for every item in the Repeating Section.  So, even after things are working for the first Spell, when I add another one, it has the same issue as the first.
1592414684
Kavini
Pro
Marketplace Creator
Sheet Author
Compendium Curator
I think some of the variables in your setAttrs are undefined? Giving setvalue a default might resolve this issue? I.e: setvalue = v[field[a]] || 0; You'll know what (if any) value is appropriate. A thing that's worth pointing out (if you didn't already know) is that if you add a sourceURL to your sheetworker, it'll then show up in Chrome DevTools: //# sourceURL=sheetworker.js This makes debugging sheetworkers much much easier and removes the need for console logging!
1592415538
Finderski
Pro
Sheet Author
Compendium Curator
Nic B. said: A thing that's worth pointing out (if you didn't already know) is that if you add a sourceURL to your sheetworker, it'll then show up in Chrome DevTools: //# sourceURL=sheetworker.js This makes debugging sheetworkers much much easier and removes the need for console logging! Nic, Where do I put that? And it looks like it's commented out, do I need to uncomment it?
1592415915
Kavini
Pro
Marketplace Creator
Sheet Author
Compendium Curator
I don't think it's location specific, but I tend to put it in the sheetworker as my final line: It doesn't need to be uncommented. Also worth pointing out that I've never been able to get it to work with Firefox, only Chrome. Once you've added it in, it should appear as a source in sheetsandboxworker.js:
1592416407
Finderski
Pro
Sheet Author
Compendium Curator
Cool. I've added it, but my error message hasn't changed. From Chrome, here's the full error message: I'm not seeing anywhere where it points to the sheetworker, though. And the values are being set, here's the console log that is executed before the setAttrs call:
1592430830
Finderski
Pro
Sheet Author
Compendium Curator
So, I had a little more time and so tried what Nic suggestion and made this change: setvalue = v[field[a]] || "something defaulty"; Adding that || with another string resolves the issue.  It still uses the value displayed in the object as defined in the console, so I'm getting the correct value and not the "something defaulty" so I don't know why that made a difference, but with that little bit, I'm getting the correct output now. Can anyone explain why that fixes it, because the variable is clearly being set with "Spellcasting" and "Weird Science" before the setAttrs call...?
1592432876
Kavini
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Sorry, I think I confused you more with the ChromeDevTools, using it allows you to debug javascript in a much easier way than console logging. More info here. That said, I just noticed: you have ritualname defined in the array spellskillnamelist, but no HTML fields to match. This might be the cause of your problems?
1592433972
Finderski
Pro
Sheet Author
Compendium Curator
Nic, nah...I knew it was for helping debug JS...I just didn't see "sheetworker" next to the error message (and I didn't really notice it next to the console log until a moment later). However, your sharp eye in spotting "ritualname" did solve the problem completely. Totally missed that one in there. :-/ Thanks for the help! That has put my mind at rest, because a mystery is now solved. :)