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] setAttrs not working...?

1549014535

Edited 1549015329
Finderski
Pro
Sheet Author
Compendium Curator
I'm working on a sheet upgrade script (still...<sigh>) and am having problem with setAttrs not working 100% correctly and wondering: a) is anyone else seeing this problem, and b) what am I doing wrong...? Here's my sheet worker: function convertRS (originSection, destinationSection, ofieldArray, dfieldArray, daddlfieldArray, defaultValues) { /*------ example of call ------ ||  originSection = section (without repeating_) fields will be migrated FROM ||  destinationSection = section (without repeating_) fields will be migrated TO  ||  ofieldArray = Array of Fields that need to be migrated ||  dfieldArray = Array of Fields the ofieldArray will be mapped to ||  NOTE: The number of fields in the ofieldArray and dfieldArray should be the same ||  daddlfieldArray = Additional fields in the destination section that may not be in the original section  ||  defaultValues = Default values for list of fields in daddlfieldArray ||  NOTE: The number of fields in the daddlfieldArray and defaultValues should be the same ||   ||  Example: ||  var hindranceFields = ["hindrance","hindrancedescription"]; ||  convertRS("mhindrances","hindrances",hindranceFields,hindranceFields); --------*/ console.log("originSection: " + originSection); console.log("destinationSection: " + destinationSection); console.log("ofieldArray: " + ofieldArray); console.log("dfieldarray: " + dfieldArray); console.log("Number of Entries in ofieldArray: " + ofieldArray.length); console.log("Number of Entries in dfieldArray: " + dfieldArray.length); let originRS = "repeating_"+originSection; getSectionIDs(originRS, function(idArray) { if (idArray.length > 0) { console.log("originSection IDs: " + idArray); let oldAttrs = []; for (let a=0; a < idArray.length; a++) { for (let b=0; b < ofieldArray.length; b++) { oldAttrs[oldAttrs.length] = originRS + "_" + idArray[a] + "_" + ofieldArray[b]; } } getAttrs(oldAttrs, function(v) { let sattrs = {}; for(let i=0; i < idArray.length; i++) { let newrowid = generateRowID(); console.log("~~~~ ConvertRS Iteration " + i + ":: for Section: "+ originSection + ":: id generated: " + newrowid +" ~~~~"); let originRF = "repeating_" + originSection + "_" + idArray[i] + "_"; let destinationRF = "repeating_" + destinationSection + "_" + newrowid + "_"; //migrate original fields to new fields for(var r=0; r < ofieldArray.length; r++) { let getORF = '', putdestinationRF = ''; console.log("********************"); console.log("** originRF: "+originRF+ofieldArray[r]); console.log("** destinationRF: "+destinationRF+dfieldArray[r]); console.log("********************"); getORF = originRF+ofieldArray[r]; console.log(i+"-"+r+") Current value of getORF: "+getORF+": "+v[getORF]); putdestinationRF = destinationRF+dfieldArray[r]; sattrs[putdestinationRF]=v[getORF]; } //Check to see if we need to set any default values if (daddlfieldArray.length > 0 && daddlfieldArray.length === defaultValues.length) { console.log("!! Need to set some additional fields !!"); //Set default value for other fields for(let r=0; r < daddlfieldArray.length; r++) { let getORF = '', putdestinationRF = ''; console.log("********************"); console.log("** destinationRF: "+destinationRF+daddlfieldArray[r]); console.log("********************"); putdestinationRF = destinationRF+daddlfieldArray[r]; sattrs[putdestinationRF] = defaultValues[r]; } } else { console.log("!! No additional fields to set OR the number of fields doesn't match the number of values !!"); } } console.log("##### sattrs: " + JSON.stringify(sattrs) + " #####"); setAttrs(sattrs, {silent: true}); }); } else { console.log("<===== "+originSection+" had no rows =====>"); } }); } When I upgrade the sheet, I get this in the console... ##### sattrs: {"repeating_weapons_-LXYYz4ay-fSFk1SfjKj_weapon":"Colt Army (.44) x2","repeating_weapons_-LXYYz4ay-fSFk1SfjKj_range":"12/24/48","repeating_weapons_-LXYYz4ay-fSFk1SfjKj_rof":"1","repeating_weapons_-LXYYz4ay-fSFk1SfjKj_dmgnumdice":"2","repeating_weapons_-LXYYz4ay-fSFk1SfjKj_dmgdietype":"d6!","repeating_weapons_-LXYYz4ay-fSFk1SfjKj_dmgbonusnum":"2","repeating_weapons_-LXYYz4ay-fSFk1SfjKj_weaponweight":"4","repeating_weapons_-LXYYz4ay-fSFk1SfjKj_weaponnotes":"GSoD: +1 dmg; Shots: 6; Single-Action","repeating_weapons_-LXYYz4ay-fSFk1SfjKj_damageatt":"na","repeating_weapons_-LXYYz4ay-fSFk1SfjKj_weaponcarried":"on","repeating_weapons_-LXYYz4eOd5LpvgYk4t9_weapon":"Winchester '73 (.44)","repeating_weapons_-LXYYz4eOd5LpvgYk4t9_range":"24/48/96","repeating_weapons_-LXYYz4eOd5LpvgYk4t9_rof":"1","repeating_weapons_-LXYYz4eOd5LpvgYk4t9_dmgnumdice":"2","repeating_weapons_-LXYYz4eOd5LpvgYk4t9_dmgdietype":"d8!","repeating_weapons_-LXYYz4eOd5LpvgYk4t9_dmgbonusnum":"1","repeating_weapons_-LXYYz4eOd5LpvgYk4t9_weaponweight":"7","repeating_weapons_-LXYYz4eOd5LpvgYk4t9_weaponnotes":"GSoD: +1 dmg; Shots: 15; AP 2","repeating_weapons_-LXYYz4eOd5LpvgYk4t9_damageatt":"na","repeating_weapons_-LXYYz4eOd5LpvgYk4t9_weaponcarried":"on","repeating_weapons_-LXYYz4j2omEYsuh6BuG_weapon":"Dbl Barrel Shotgun","repeating_weapons_-LXYYz4j2omEYsuh6BuG_range":"12/24/48","repeating_weapons_-LXYYz4j2omEYsuh6BuG_dmgnumdice":"2","repeating_weapons_-LXYYz4j2omEYsuh6BuG_dmgdietype":"d6!","repeating_weapons_-LXYYz4j2omEYsuh6BuG_dmgbonusnum":"1","repeating_weapons_-LXYYz4j2omEYsuh6BuG_weaponweight":"8","repeating_weapons_-LXYYz4j2omEYsuh6BuG_weaponnotes":"GSoD: +1 dmg; Shots: 2; +2 Shooting Rolls","repeating_weapons_-LXYYz4j2omEYsuh6BuG_damageatt":"na","repeating_weapons_-LXYYz4j2omEYsuh6BuG_weaponcarried":"on"} ##### and... ##### sattrs: {"repeating_weapons_-LXYYz4QPMvMb84JLXrf_weapon":"Brass Knuckles","repeating_weapons_-LXYYz4QPMvMb84JLXrf_dmgnumdice":"1","repeating_weapons_-LXYYz4QPMvMb84JLXrf_dmgbonusnum":"1","repeating_weapons_-LXYYz4QPMvMb84JLXrf_weaponweight":"1","repeating_weapons_-LXYYz4QPMvMb84JLXrf_weaponnotes":"GSoD: +1 dmg","repeating_weapons_-LXYYz4QPMvMb84JLXrf_weaponcarried":"on","repeating_weapons_-LXYYz4UjZHr59qveESU_weapon":"Bowie Knife","repeating_weapons_-LXYYz4UjZHr59qveESU_dmgnumdice":"1","repeating_weapons_-LXYYz4UjZHr59qveESU_dmgbonusnum":"2","repeating_weapons_-LXYYz4UjZHr59qveESU_weaponweight":"2","repeating_weapons_-LXYYz4UjZHr59qveESU_weaponnotes":"AP 1; GSoD: +1 dmg","repeating_weapons_-LXYYz4UjZHr59qveESU_weaponcarried":"on","repeating_weapons_-LXYYz4XdTWWLFrvA4KS_weapon":"Saber","repeating_weapons_-LXYYz4XdTWWLFrvA4KS_dmgnumdice":"1","repeating_weapons_-LXYYz4XdTWWLFrvA4KS_dmgdietype":"6!","repeating_weapons_-LXYYz4XdTWWLFrvA4KS_dmgbonusnum":"1","repeating_weapons_-LXYYz4XdTWWLFrvA4KS_weaponweight":"5","repeating_weapons_-LXYYz4XdTWWLFrvA4KS_weaponnotes":"GSoD: +1 dmg","repeating_weapons_-LXYYz4XdTWWLFrvA4KS_weaponcarried":"on"} ##### Made easier to read: {     "repeating_weapons_-LXYYz4ay-fSFk1SfjKj_weapon": "Colt Army (.44) x2",     "repeating_weapons_-LXYYz4ay-fSFk1SfjKj_range": "12/24/48",     "repeating_weapons_-LXYYz4ay-fSFk1SfjKj_rof": "1",     "repeating_weapons_-LXYYz4ay-fSFk1SfjKj_dmgnumdice": "2",     "repeating_weapons_-LXYYz4ay-fSFk1SfjKj_dmgdietype": "d6!",     "repeating_weapons_-LXYYz4ay-fSFk1SfjKj_dmgbonusnum": "2",     "repeating_weapons_-LXYYz4ay-fSFk1SfjKj_weaponweight": "4",     "repeating_weapons_-LXYYz4ay-fSFk1SfjKj_weaponnotes": "GSoD: +1 dmg; Shots: 6; Single-Action",     "repeating_weapons_-LXYYz4ay-fSFk1SfjKj_damageatt": "na",     "repeating_weapons_-LXYYz4ay-fSFk1SfjKj_weaponcarried": "on",     "repeating_weapons_-LXYYz4eOd5LpvgYk4t9_weapon": "Winchester '73 (.44)",     "repeating_weapons_-LXYYz4eOd5LpvgYk4t9_range": "24/48/96",     "repeating_weapons_-LXYYz4eOd5LpvgYk4t9_rof": "1",     "repeating_weapons_-LXYYz4eOd5LpvgYk4t9_dmgnumdice": "2",     "repeating_weapons_-LXYYz4eOd5LpvgYk4t9_dmgdietype": "d8!",     "repeating_weapons_-LXYYz4eOd5LpvgYk4t9_dmgbonusnum": "1",     "repeating_weapons_-LXYYz4eOd5LpvgYk4t9_weaponweight": "7",     "repeating_weapons_-LXYYz4eOd5LpvgYk4t9_weaponnotes": "GSoD: +1 dmg; Shots: 15; AP 2",     "repeating_weapons_-LXYYz4eOd5LpvgYk4t9_damageatt": "na",     "repeating_weapons_-LXYYz4eOd5LpvgYk4t9_weaponcarried": "on",     "repeating_weapons_-LXYYz4j2omEYsuh6BuG_weapon": "Dbl Barrel Shotgun",     "repeating_weapons_-LXYYz4j2omEYsuh6BuG_range": "12/24/48",     "repeating_weapons_-LXYYz4j2omEYsuh6BuG_dmgnumdice": "2",     "repeating_weapons_-LXYYz4j2omEYsuh6BuG_dmgdietype": "d6!",     "repeating_weapons_-LXYYz4j2omEYsuh6BuG_dmgbonusnum": "1",     "repeating_weapons_-LXYYz4j2omEYsuh6BuG_weaponweight": "8",     "repeating_weapons_-LXYYz4j2omEYsuh6BuG_weaponnotes": "GSoD: +1 dmg; Shots: 2; +2 Shooting Rolls",     "repeating_weapons_-LXYYz4j2omEYsuh6BuG_damageatt": "na",     "repeating_weapons_-LXYYz4j2omEYsuh6BuG_weaponcarried": "on" } and... {     "repeating_weapons_-LXYYz4QPMvMb84JLXrf_weapon": "Brass Knuckles",     "repeating_weapons_-LXYYz4QPMvMb84JLXrf_dmgnumdice": "1",     "repeating_weapons_-LXYYz4QPMvMb84JLXrf_dmgbonusnum": "1",     "repeating_weapons_-LXYYz4QPMvMb84JLXrf_weaponweight": "1",     "repeating_weapons_-LXYYz4QPMvMb84JLXrf_weaponnotes": "GSoD: +1 dmg",     "repeating_weapons_-LXYYz4QPMvMb84JLXrf_weaponcarried": "on",     "repeating_weapons_-LXYYz4UjZHr59qveESU_weapon": "Bowie Knife",     "repeating_weapons_-LXYYz4UjZHr59qveESU_dmgnumdice": "1",     "repeating_weapons_-LXYYz4UjZHr59qveESU_dmgbonusnum": "2",     "repeating_weapons_-LXYYz4UjZHr59qveESU_weaponweight": "2",     "repeating_weapons_-LXYYz4UjZHr59qveESU_weaponnotes": "AP 1; GSoD: +1 dmg",     "repeating_weapons_-LXYYz4UjZHr59qveESU_weaponcarried": "on",     "repeating_weapons_-LXYYz4XdTWWLFrvA4KS_weapon": "Saber",     "repeating_weapons_-LXYYz4XdTWWLFrvA4KS_dmgnumdice": "1",     "repeating_weapons_-LXYYz4XdTWWLFrvA4KS_dmgdietype": "6!",     "repeating_weapons_-LXYYz4XdTWWLFrvA4KS_dmgbonusnum": "1",     "repeating_weapons_-LXYYz4XdTWWLFrvA4KS_weaponweight": "5",     "repeating_weapons_-LXYYz4XdTWWLFrvA4KS_weaponnotes": "GSoD: +1 dmg",     "repeating_weapons_-LXYYz4XdTWWLFrvA4KS_weaponcarried": "on" } It areas in bold, are where the problem exists...in the case of the first, not all the data is written correctly (I'll try post a screen sheet after I save this...don't want to lose everything I've written...), and in the case of the second, the brass knuckles show up, but the other two weapons aren't there at all.  There are some fields missing from the Brass Knuckles, too--like the damage die type, but given that it's a d4, it's very likely the origin field was just a default value...so, perhaps there's "nothing" for the sheet worker to grab? Thoughts on what the problem may be? Here's what the character sheet entry looks like after the sheet worker executes: Here's the source (two images, because I'm taking two different repeating sections and combining them into a single one: I'll try a reply to get the other images in...(I hate trying to get images in forum posts...I waste more time doing it...:-/) Edit: I give up...needless to say, the damage should be strength 2 d6 + 0 for the Dbl Barrel Shotgun. For the brass knuckles, there should be a 1 after the 1d4, but more importantly, there should be two more weapons after it (Saber and Bowie knife).
1549029345
GiGs
Pro
Sheet Author
API Scripter
On the sharing images part: I always upload my images to imgur first, then embed them in the roll20's post via link rather than upload. I have never had this method fail. Thats a really complex sheet setup to try to debug remotely. Does the sattrs object have all correct information when printed to log? So the error is occurring at the moment of the the setAttrs function? If that's the case, I'd guess the issue is not the sheet worker, but something in the html of the new repeating section. Can you post that?
1549029575
GiGs
Pro
Sheet Author
API Scripter
Also this syntax surprised me: oldAttrs[oldAttrs.length] = originRS + "_" + idArray[a] + "_" + ofieldArray[b]; I didnt know you could do that, I always use oldAttrs.push(originRS + "_" + idArray[a] + "_" + ofieldArray[b]);
1549058594
Finderski
Pro
Sheet Author
Compendium Curator
GiGs said: Thats a really complex sheet setup to try to debug remotely. Does the sattrs object have all correct information when printed to log? So the error is occurring at the moment of the the setAttrs function? If that's the case, I'd guess the issue is not the sheet worker, but something in the html of the new repeating section. Can you post that? The printed log has the correct information, so it's occurring within the setAttrs function.  The weird thing is all the (html) fields are the same for all the weapons, and some are working properly and some are not... :-/ Anyway, here's the code for the new repeating section: <fieldset class="repeating_weapons"> <div class='sheet-weaponitem'> <button type='roll' class="sheet-button" name='roll_tWeapon' value="@{weaponroll}"><input type="hidden" name="attr_weaponbutton" class="sheet-weaponbutton" value="1" /><span class="sheet-buttonand" data-i18n="attack-and-damage-abbr">Atk+Dmg</span><span class="sheet-buttondo" data-i18n="damage">Damage</span></button> <button type='roll' style='display: none;' name='roll_dmg' value='@{damageOnly}'></button> <input type='text' class='sheet-weapon' name='attr_weapon' data-i18n-placeholder="weapon" placeholder="Weapon" /> <input type='text' class='sheet-range' name='attr_range' data-i18n-placeholder="range" placeholder="Range" /> <input type='number' style="width: 35px;" class='sheet-rof' name='attr_rof' data-i18n-placeholder="rate-of-fire-abbr" placeholder="ROF" /> <input type='text' class='sheet-damage' name='attr_weapondamage' value="Str+d4" readonly /> <input type="number" style="width:50px;" class='sheet-weaponap' name='attr_weaponap' /> <input type='text' class='sheet-shots' name='attr_shots' data-i18n-placeholder="number-of-shots-shortened" placeholder="Shots" /> <input type='number' style="width:65px;" class='sheet-weaponweight' name='attr_weaponweight' data-i18n-placeholder="weight-abbr" placeholder="Wt" /> <div class='sheet-weaponcarried'><input type='checkbox' name='attr_weaponcarried' /></div> <input class='sheet-moreweapon' type='checkbox' name='attr_showweaponconfig' checked /><span>y</span> <textarea name='attr_weaponnotes' class='sheet-weaponnotes' data-i18n-placeholder="notes" placeholder="Notes"></textarea> <div class="sheet-weaponconfig"> <label class="sheet-configlabels" data-i18n="button-behavior">Button Behavior</label> <select name="attr_weaponbutton" class="sheet-weaponbutton"> <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 type="hidden" name="attr_weaponbutton" class="sheet-weaponbutton" /> <div class='sheet-weaponskill'> <label class="sheet-configlabels" data-i18n="skill">Skill</label> <select name="attr_weaponskill" class="sheet-weaponbutton" value="1"> <option value="fighting" data-i18n="fighting" selected>Fighting</option> <option value="athletics" data-i18n="athletics">Athletics</option> <option value="shooting" data-i18n="shooting">Shooting</option> <option value="throwing" data-i18n="throwing">Throwing</option> <option value="unskilled" data-i18n="unskilled">Unskilled</option> </select> </div> <div class='sheet-weapondamage'> <label class='sheet-configlabels' data-i18n="damage">Damage</label> <select class='sheet-weaponatt' name="attr_damageatt"> <option value="na" data-i18n="not-applicable-abbr">N/A</option> <option value="strength" data-i18n="strength" selected>Strength</option> <option value="agility" data-i18n="agility">Agility</option> <option value="smarts" data-i18n="smarts">Smarts</option> <option value="spirit" data-i18n="spirit">Spirit</option> <option value="vigor" data-i18n="vigor">Vigor</option> </select> + <input type="number" class="sheet-weaponnum" name="attr_dmgnumdice" style="text-align: right;" value="1" /> <select name="attr_dmgdietype" class="sheet-dtype"> <option value="d4!">d4</option> <option value="d6!">d6</option> <option value="d8!">d8</option> <option value="d10!">d10</option> <option value="d12!">d12</option> <option value="d20!">d20</option> </select> + <input type="text" class="sheet-weaponnum" name="attr_dmgbonusnum" /> </div> </div> <!-- Hidden Fields for the roll button(s), etc --> <input type='hidden' name='attr_weaponroll' value='@{damageOnly}' /> <input type='hidden' name='attr_skillNDamage' value="&{template:roll} {{trait=Fighting}} {{source=@{weapon}}} @{rolltFighting} {{button=y}} {{DmgRoll=[Roll Damage](~repeating_weapons_dmg) }}" /> <!--Used for Skill and Damage roll --> <input type='hidden' name='attr_damageOnly' value='@{dmgTemplate}' /> <!-- Used for Damage Only --> <!-- Build the Damage Roll Template Info --> <input type='hidden' name='attr_weapondmg' value="@{strength_rank}+1d4!" /> <!-- the damage formula --> <input type='hidden' name='attr_bonusdmg' value='1d6!' /> <input type='text' style='display: none;' name='attr_dmgTemplate' value='&{template:damage} {{name=@{character_name}}} {{source=@{weapon} }} {{dmg_rank=@{weapondamage}}} {{dmg_roll=[[@{weapondmg} + @{damagemods}]]}} {{bonus_die=[[@{vbonusdamage}]]}} {{showap=[[1d0+@{weaponap}]]}} {{ap=@{weaponap}}} {{notes=@{weaponnotes}}} {{button=y}} {{DmgRoll=[Re-Roll Damage](~repeating_weapons_dmg) }}' /> </div> </fieldset>
1549218674
Finderski
Pro
Sheet Author
Compendium Curator
UPDATE: Figured something out...it's because some of the incoming fields are blank (no value entered) and that's causing problems.  So...if you run into this problem, you may just want to check the typeof and if it's "undefined" set something value regardless...I haven't messed around to see if I could set it as blank.  But, anyway, mystery solved (at least for now).
1549219230
GiGs
Pro
Sheet Author
API Scripter
well done! That sounds like good advice.