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

[Splittermond] "TypeError: str is undefined"

1636474117

Edited 1636474151
Loki
Sheet Author
Hi! I'm currently working on an importer for npc data. When it's ready the players (or the GM) can simply copy a creature from a sourcebook (PDF) and copy it into a textfeld in the character sheet that then translates the data into a creature and fills the npc character sheet with the given data. This worked fine for attributes but with skills I'm getting a strange error. The click listener for the import button delivers the content of the npc.skills array that I filled beforehand with the skills. This looks like this: As you can see every array element is one skill separated with a whitespace from it's value. The method importNsc then splits every array element at the position of the whitespaces and separates skill and value: function importNsc(nsc) { let vAttributes = ["ausstrahlungnsc","beweglichkeitnsc","intuitionnsc","konstitutionnsc","mystiknsc","staerkensc","verstandnsc","willenskraftnsc","groessenklassensc","geschwindigkeitnsc","lebenspunktensc","fokusnscgesamt","verteidigungnsc","schadensreduktionnsc","koerperlicherwiderstandnsc","geistigerwiderstandnsc"]; let vSkills = {"anführen":"anfuehren","geschichte und mythen":"geschichteundmythen","länderkunde":"laenderkunde","schlösser und fallen":"schloesserundfallen","straßenkunde":"strassenkunde","zähigkeit":"zaehigkeit","stärkungsmagie":"staerkungsmagie"}; let newRowId; let update = {}; let temp = ""; for (var i = 0; i < nsc.attributes.length; i++) { let attribute = vAttributes[i]; let value = nsc.attributes[i]; update[attribute] = +value; } nsc.fertigkeiten[0] = " ".concat(nsc.fertigkeiten[0]); for (var i = 0; i < nsc.fertigkeiten.length; i++) { let skill = nsc.fertigkeiten[i].split(" ")[1]; let value = parseInt(nsc.fertigkeiten[i].split(" ")[2], 10) || 0; if (skill in vSkills) { skill = vSkills[skill]; } console.log("skill:" + skill + ",value:" + value); newRowId = generateRowID(); update['repeating_fertigkeitennsc_' + newRowId + '_fertigkeitnsc'] = skill; update['repeating_fertigkeitennsc_' + newRowId + '_fertigkeitswertnsc'] = +value; } setAttrs(update); } The repeating_row (repeating_fertigkeitennsc) looks like this: It just consists of a select element for the skill, a text field for the value, a roll button and a checkbox for a special skill mode. In code: <fieldset class="repeating_fertigkeitennsc"> <select name="attr_fertigkeitnsc""> <option value="akrobatik">Akrobatik</option> <option value="alchemie">Alchemie</option> <option value="anfuehren">Anführen</option> <option value="arkanekunde">Arkane Kunde</option> <option value="athletik">Athletik</option> <option value="darbietung">Darbietung</option> <option value="diplomatie">Diplomatie</option> <option value="edelhandwerk">Edelhandwerk</option> <option value="empathie">Empathie</option> <option value="entschlossenheit">Entschlossenheit</option> <option value="fingerfertigkeit">Fingerfertigkeit</option> <option value="geschichteundmythen">Geschichte & Mythen</option> <option value="handwerk">Handwerk</option> <option value="heilkunde">Heilkunde</option> <option value="heimlichkeit">Heimlichkeit</option> <option value="jagdkunst">Jagdkunst</option> <option value="laenderkunde">Länderkunde</option> <option value="naturkunde">Naturkunde</option> <option value="redegewandtheit">Redegewandtheit</option> <option value="schloesserundfallen">Schlösser & Fallen</option> <option value="schwimmen">Schwimmen</option> <option value="seefahrt">Seefahrt</option> <option value="strassenkunde">Straßenkunde</option> <option value="tierfuehrung">Tierführung</option> <option value="ueberleben">Überleben</option> <option value="wahrnehmung">Wahrnehmung</option> <option value="zaehigkeit">Zähigkeit</option> <option value="nix">------ Magieschulen ------</option> <option value="bannmagie">Bannmagie</option> <option value="beherrschungsmagie">Beherrschungsmagie</option> <option value="bewegungsmagie">Bewegungsmagie</option> <option value="erkenntnismagie">Erkenntnismagie</option> <option value="felsmagie">Felsmagie</option> <option value="feuermagie">Feuermagie</option> <option value="heilungsmagie">Heilungsmagie</option> <option value="illusionsmagie">Illusionsmagie</option> <option value="kampfmagie">Kampfmagie</option> <option value="lichtmagie">Lichtmagie</option> <option value="naturmagie">Naturmagie</option> <option value="schattenmagie">Schattenmagie</option> <option value="schicksalsmagie">Schicksalsmagie</option> <option value="schutzmagie">Schutzmagie</option> <option value="staerkungsmagie">Stärkungsmagie</option> <option value="todesmagie">Todesmagie</option> <option value="verwandlungsmagie">Verwandlungsmagie</option> <option value="wassermagie">Wassermagie</option> <option value="windmagie">Windmagie</option> </select> <input type=number name="attr_fertigkeitswertnsc" value="0" min="0"> <button type="action" name="act_skill" class="sheet-ability-button">0</button> <input type="checkbox" name="attr_gm" value="1" /> </fieldset> But I noticed that Roll20 gives me an error everytime I click on the Import button (only the first time though, when I click it a second time, everything works fine): This is my debug output followed by the error. The debug output looks fine, there doesn't seem to be anything wrong. Now comes the strange part: The said error occurs exactly three times during the import and always on the exact same three skills (akrobatik, entschlossenheit, zaehigkeit). If I remove those three skills from the import string everything works smoothly. Additionally I also add this three skills to the same repeating section on sheet:opened and there they don't produce any errors: getSectionIDs("fertigkeitennsc", function(idarray) { if (idarray.length == 0) { var newrowattrs = {}; var newrowid = generateRowID(); newrowattrs["repeating_fertigkeitennsc_" + newrowid + "_fertigkeitnsc"] = "akrobatik"; <------ newrowid = generateRowID(); newrowattrs["repeating_fertigkeitennsc_" + newrowid + "_fertigkeitnsc"] = "athletik"; newrowid = generateRowID(); newrowattrs["repeating_fertigkeitennsc_" + newrowid + "_fertigkeitnsc"] = "entschlossenheit"; <----- newrowid = generateRowID(); newrowattrs["repeating_fertigkeitennsc_" + newrowid + "_fertigkeitnsc"] = "heimlichkeit"; newrowid = generateRowID(); newrowattrs["repeating_fertigkeitennsc_" + newrowid + "_fertigkeitnsc"] = "wahrnehmung"; newrowid = generateRowID(); newrowattrs["repeating_fertigkeitennsc_" + newrowid + "_fertigkeitnsc"] = "zaehigkeit"; <----- setAttrs(newrowattrs); } }); (FYI: This is because this are the default skills that every npc has, so I add them anyway if the repeating row is empty because the gm has to add them anyway - but removing this code doesn't make any difference). I'm coming to the following conclusion: Since the error only occurs the first time I import the skills and it doesn't occur again on further imports unless I reload the page it must have something to do with uninitialized objects. But I really don't know what's wrong with this three specific skills that cause this error. I double checked the entries in the <input> object but they're exactly the same. I know this is a terribly specific problem but maybe somebody has a hint for me. Cheers!
1636474903

Edited 1636475082
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I'm not entirely sure where the error is coming from, however I do have a small bit of code critique. Instead of using the for construction, use a forEach and you can do the extraction of the skill name and value all at once: nsc.fertigkeiten.forEach((fertigkeiten)=>{ let [,skill,value] = fertigkeiten.split(" "); value = +value || 0; if (skill in vSkills) {//A quicker check would be to simply do if(vSkills[skill]) skill = vSkills[skill]; } console.log("skill:" + skill + ",value:" + value); newRowId = generateRowID(); update['repeating_fertigkeitennsc_' + newRowId + '_fertigkeitnsc'] = skill; update['repeating_fertigkeitennsc_' + newRowId + '_fertigkeitswertnsc'] = +value; } I'm also unsure what the purpose of this bit of code is: nsc.fertigkeiten[0] = " ".concat(nsc.fertigkeiten[0]); Sorry I don't have any hard answers for you though. Edit: I might also recommend trimming your skill/value combos before placing them in the array so that you don't have the extraneous leading space. That's a potential failure point for the parsing if somehow a skill/value gets passed in with a different number of leading spaces.
1636530631

Edited 1636530645
Oosh
Sheet Author
API Scripter
I would suggest moving your debug line further up. Log each value of this array: nsc.fertigkeiten before you process it. It looks like one of your String instance methods (either .split() or .concat()) is being passed an undefined value. You can also 'cast' the value by using a template literal to prevent type errors in String methods: nsc.fertigkeiten[0] = " ".concat(`${nsc.fertigkeiten[0]}`); Whether or not this is appropriate depends on whether your function can handle being fed a "null" or "undefined" string without messing anything up.
1636548013

Edited 1636549502
Loki
Sheet Author
Hey! Thank you Scott and Oosh! That brought my a step further. Obviousley the .split() was causing some issues because after replacing it with a .match() and a regex I only get one error instead of three. function importNsc(nsc) { let vAttributes = ["ausstrahlungnsc","beweglichkeitnsc","intuitionnsc","konstitutionnsc","mystiknsc","staerkensc","verstandnsc","willenskraftnsc","groessenklassensc","geschwindigkeitnsc","lebenspunktensc","fokusnscgesamt","verteidigungnsc","schadensreduktionnsc","koerperlicherwiderstandnsc","geistigerwiderstandnsc"]; let vSkills = {"anführen":"anfuehren","tierführung":"tierfuehrung","geschichte und mythen":"geschichteundmythen","länderkunde":"laenderkunde","schlösser und fallen":"schloesserundfallen","straßenkunde":"strassenkunde","zähigkeit":"zaehigkeit","stärkungsmagie":"staerkungsmagie"}; let newRowId; let waffen = nsc.waffen; let update = {}; let temp = ""; let ini = 0; for (var i = 0; i < nsc.attributes.length; i++) { let attribute = vAttributes[i]; let value = nsc.attributes[i]; update[attribute] = +value; } nsc.fertigkeiten.forEach((fertigkeit) => { console.log("Fertigkeit:" + fertigkeit); let skill = fertigkeit.replace(/\s/g,'').match(/[a-zA-Zäöü]+/g) || "test";     let value = parseInt(fertigkeit.replace(/\s/g,'').match(/[\d]+/g), 10) || 0; if(vSkills[skill]) { skill = vSkills[skill]; } console.log("skill:" + skill + ",value:" + value); newRowId = generateRowID(); update['repeating_fertigkeitennsc_' + newRowId + '_fertigkeitnsc'] = skill; update['repeating_fertigkeitennsc_' + newRowId + '_fertigkeitswertnsc'] = +value; }); [...] setAttrs(update); } I'm still getting one of the "TypeError" errors but I think both variables, skill and value, shouldn't cause any errors because they should at least have the values "test" and 0. I also added the  additional line of debug output: So what could still go wrong here? The debug output again looks fine. I'm very grateful for further tips! Cheers! [Edit] I also get a additional error of the same type when I try to clear the repeating section before adding new rows to it: getSectionIDs("repeating_fertigkeitennsc", function(idarray) { for(var i=0; i < idarray.length; i++) { removeRepeatingRow("repeating_fertigkeitennsc_" + idarray[i]); } }); nsc.fertigkeiten.forEach((fertigkeit) => { console.log("Fertigkeit:" + fertigkeit); let skill = fertigkeit.replace(/\s/g,'').match(/[a-zA-Zäöü]+/g) || "test"; let value = parseInt(fertigkeit.replace(/\s/g,'').match(/[\d]+/g), 10) || 0; if(vSkills[skill]) { skill = vSkills[skill]; } console.log("skill:" + skill + ",value:" + value); newRowId = generateRowID(); update['repeating_fertigkeitennsc_' + newRowId + '_fertigkeitnsc'] = skill; update['repeating_fertigkeitennsc_' + newRowId + '_fertigkeitswertnsc'] = +value; }); With this code I get two errors. Maybe there's something wrong with the repeating section itself? [/Edit]
1636758523
Oosh
Sheet Author
API Scripter
I notice there's a problem in your HTML - the number input in your code above is missing the quotes in type="number" .... A closer look at the error also tells me it's coming from a jQuery helper function in base.js, so there's a good chance it's being triggered by some HTML syntax errors. That would explain why your function still works despite a TypeError being thrown - it's probably not coming from your function at all :) Maybe have a look over your HTML to make sure there's no other issues!
1636763434
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Oh, that's a great catch Oosh! That error stack had been confusing the hell out of me. I wouldn't be a bit surprised if you're onto something.
1636927557
Loki
Sheet Author
Hey! Really a nice catch, Oosh! I changed the code... <fieldset class="repeating_fertigkeitennsc"> <select name="attr_fertigkeitnsc"> <option value="akrobatik">Akrobatik</option> <option value="alchemie">Alchemie</option> <option value="anfuehren">Anführen</option> <option value="arkanekunde">Arkane Kunde</option> <option value="athletik">Athletik</option> <option value="darbietung">Darbietung</option> <option value="diplomatie">Diplomatie</option> <option value="edelhandwerk">Edelhandwerk</option> <option value="empathie">Empathie</option> <option value="entschlossenheit">Entschlossenheit</option> <option value="fingerfertigkeit">Fingerfertigkeit</option> <option value="geschichteundmythen">Geschichte & Mythen</option> <option value="handwerk">Handwerk</option> <option value="heilkunde">Heilkunde</option> <option value="heimlichkeit">Heimlichkeit</option> <option value="jagdkunst">Jagdkunst</option> <option value="laenderkunde">Länderkunde</option> <option value="naturkunde">Naturkunde</option> <option value="redegewandtheit">Redegewandtheit</option> <option value="schloesserundfallen">Schlösser & Fallen</option> <option value="schwimmen">Schwimmen</option> <option value="seefahrt">Seefahrt</option> <option value="strassenkunde">Straßenkunde</option> <option value="tierfuehrung">Tierführung</option> <option value="ueberleben">Überleben</option> <option value="wahrnehmung">Wahrnehmung</option> <option value="zaehigkeit">Zähigkeit</option> <option value="nix">------ Magieschulen ------</option> <option value="bannmagie">Bannmagie</option> <option value="beherrschungsmagie">Beherrschungsmagie</option> <option value="bewegungsmagie">Bewegungsmagie</option> <option value="erkenntnismagie">Erkenntnismagie</option> <option value="felsmagie">Felsmagie</option> <option value="feuermagie">Feuermagie</option> <option value="heilungsmagie">Heilungsmagie</option> <option value="illusionsmagie">Illusionsmagie</option> <option value="kampfmagie">Kampfmagie</option> <option value="lichtmagie">Lichtmagie</option> <option value="naturmagie">Naturmagie</option> <option value="schattenmagie">Schattenmagie</option> <option value="schicksalsmagie">Schicksalsmagie</option> <option value="schutzmagie">Schutzmagie</option> <option value="staerkungsmagie">Stärkungsmagie</option> <option value="todesmagie">Todesmagie</option> <option value="verwandlungsmagie">Verwandlungsmagie</option> <option value="wassermagie">Wassermagie</option> <option value="windmagie">Windmagie</option> </select> <input type="number" name="attr_fertigkeitswertnsc" value="0" min="0"> <button type="action" name="act_skill" class="sheet-ability-button">0</button> <input type="checkbox" name="attr_gm" value="1" /> </fieldset> ... but I still get that error: I fiddled around a little bit and the problem seems to be the <select> element, because when I simply write something like newRowId = generateRowID(); update['repeating_fertigkeitennsc_' + newRowId + '_fertigkeitnsc'] = "akrobatik"; I get the same error - just with the plain text. That happens if I use any of the three words that produce this error. Whether or not I just add them in plain text like the example above or as a result of the parsed string - they produce the error. I really don't know what's going on here. Nonetheless: Thank you for  your time and help! :-) Cheers!