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

[Sheet Worker] New line in error in my repeating sections

1507728637
PadRpg
Sheet Author
API Scripter
Hi, In my new sheet, I want to use the sheet worker to calculate the skill score in a repeating section. The calcul works but when the script is executed, a new line (a copy of the current line) appears in error : Here's the HTML (the interesting part): <input name="attr_str" type="number" title="@{str}" /> <input name="attr_con" type="number" title="@{con}" /> <input name="attr_dex" type="number" title="@{dex}" /> <input name="attr_siz" type="number" title="@{siz}" /> <input name="attr_int" type="number" title="@{int}" /> <input name="attr_pow" type="number" title="@{pow}" /> <input name="attr_cha" type="number" title="@{cha}" /> <fieldset class="repeating_advancedSkills"> <input name="attr_advancedSkillName" type="text" data-i18n-place="advanced-skill-name-place" placeholder="Advanced Skill Name" /> <select name="attr_advancedSkillChar1" data-i18n-title="advanced-skill-characteristics-1-title" title="First Characteristics for Advanced Skill"> <option value="0" selected></option> <option value="str" data-i18n="STR">STR</option> <option value="con" data-i18n="CON">CON</option> <option value="dex" data-i18n="DEX">DEX</option> <option value="siz" data-i18n="SIZ">SIZ</option> <option value="int" data-i18n="INT">INT</option> <option value="pow" data-i18n="POW">POW</option> <option value="cha" data-i18n="CHA">CHA</option> </select> <select name="attr_advancedSkillChar2" data-i18n-title="advanced-skill-characteristics-2-title" title="First Characteristics for Advanced Skill"> <option value="0" selected></option> <option value="str" data-i18n="STR">STR</option> <option value="con" data-i18n="CON">CON</option> <option value="dex" data-i18n="DEX">DEX</option> <option value="siz" data-i18n="SIZ">SIZ</option> <option value="int" data-i18n="INT">INT</option> <option value="pow" data-i18n="POW">POW</option> <option value="cha" data-i18n="CHA">CHA</option> </select> <input name="attr_advancedSkillBase" readonly="readonly" type="number" title="@{advancedSkillBase}" /> <input name="attr_advancedSkillMod" type="number" title="@{advancedSkillMod}" value="0" /> <input name="attr_advancedSkill" readonly="readonly" type="number" title="@{advancedSkill}" /> </fieldset> And here's the script part : on("change:repeating_advancedskills", function() { TAS.repeating('advancedSkills') .attrs('str','con','dex','siz','int','pow','cha') .fields('advancedSkillChar1','advancedSkillChar2','advancedSkillMod','advancedSkillBase','advancedSkill')                 .each(function(r,f){ var charVal1=0; var charVal2=0; if(r.advancedSkillChar1=='str'){ charVal1=parseInt(f.F["str"]); } if(r.advancedSkillChar1=='con'){ charVal1=parseInt(f.F["con"]); } if(r.advancedSkillChar1=='dex'){ charVal1=parseInt(f.F["dex"]); } if(r.advancedSkillChar1=='siz'){ charVal1=parseInt(f.F["siz"]); } if(r.advancedSkillChar1=='int'){ charVal1=parseInt(f.F["int"]); } if(r.advancedSkillChar1=='pow'){ charVal1=parseInt(f.F["pow"]); } if(r.advancedSkillChar1=='cha'){ charVal1=parseInt(f.F["cha"]); } if(r.advancedSkillChar2=='str'){ charVal2=parseInt(f.F["str"]); } if(r.advancedSkillChar2=='con'){ charVal2=parseInt(f.F["con"]); } if(r.advancedSkillChar2=='dex'){ charVal2=parseInt(f.F["dex"]); } if(r.advancedSkillChar2=='siz'){ charVal2=parseInt(f.F["siz"]); } if(r.advancedSkillChar2=='int'){ charVal2=parseInt(f.F["int"]); } if(r.advancedSkillChar2=='pow'){ charVal2=parseInt(f.F["pow"]); } if(r.advancedSkillChar2=='cha'){ charVal2=parseInt(f.F["cha"]); } r.advancedSkillBase=charVal1 + charVal2; r.advancedSkill=charVal1 + charVal2 + parseInt(r.advancedSkillMod); }) .execute(); }); I'm using the script "TheAaronSheet" script to manage the repeating sections. Thanks for the future help !
1507732820
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
This is a problem I've seen with using TAS to interact with repeating sections as well. Check to see what rows it is returning: on("change:repeating_advancedskills", function() { TAS.repeating('advancedSkills') .attrs('str','con','dex','siz','int','pow','cha') .fields('advancedSkillChar1','advancedSkillChar2','advancedSkillMod','advancedSkillBase','advancedSkill')                 .tap((rowSet,attrSet)=>{ TAS.log('rowSet: '+JSON.stringify(rowSet)); TAS.log('attrSet: '+JSON.stringify(attrSet)); }) .each(function(r,f){ var charVal1=0; var charVal2=0; if(r.advancedSkillChar1=='str'){ charVal1=parseInt(f.F["str"]); } if(r.advancedSkillChar1=='con'){ charVal1=parseInt(f.F["con"]); } if(r.advancedSkillChar1=='dex'){ charVal1=parseInt(f.F["dex"]); } if(r.advancedSkillChar1=='siz'){ charVal1=parseInt(f.F["siz"]); } if(r.advancedSkillChar1=='int'){ charVal1=parseInt(f.F["int"]); } if(r.advancedSkillChar1=='pow'){ charVal1=parseInt(f.F["pow"]); } if(r.advancedSkillChar1=='cha'){ charVal1=parseInt(f.F["cha"]); } if(r.advancedSkillChar2=='str'){ charVal2=parseInt(f.F["str"]); } if(r.advancedSkillChar2=='con'){ charVal2=parseInt(f.F["con"]); } if(r.advancedSkillChar2=='dex'){ charVal2=parseInt(f.F["dex"]); } if(r.advancedSkillChar2=='siz'){ charVal2=parseInt(f.F["siz"]); } if(r.advancedSkillChar2=='int'){ charVal2=parseInt(f.F["int"]); } if(r.advancedSkillChar2=='pow'){ charVal2=parseInt(f.F["pow"]); } if(r.advancedSkillChar2=='cha'){ charVal2=parseInt(f.F["cha"]); } r.advancedSkillBase=charVal1 + charVal2; r.advancedSkill=charVal1 + charVal2 + parseInt(r.advancedSkillMod); }) .execute(); });
1507733460
PadRpg
Sheet Author
API Scripter
Here's what I've got : Log:  rowSet: {"-kwaufvhw9zub6rvihaq":{"advancedSkillChar1":"str","advancedSkillChar2":"0","advancedSkillMod":"0","advancedSkillBase":11,"advancedSkill":11}}  Log:  attrSet: {"str":"11","con":"14","dex":"17","siz":"12","int":"16","pow":"15","cha":"14"}  In the console, it's triggered twice.
1507733938
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hmm, gonna have to get Aaron in here to see what he says. I would have expected there to be two objects in the rowset.
1507734188
PadRpg
Sheet Author
API Scripter
Thanks. I had almost no doubt about that because it removed both lines at the same time. I'll wait for Aaron to take a look.
1507735021
The Aaron
Pro
API Scripter
For the record, you could simplify your .each() to this: .each(function(r,f){ var charVal1=f.I[r.advancedSkillChar1]||0; var charVal2=f.I[r.advancedSkillChar2]||0; r.advancedSkillBase=charVal1 + charVal2; r.advancedSkill=charVal1 + charVal2 + parseInt(r.advancedSkillMod); }) .I will do a parseInt() implicitly and the || 0 will set it to 0 if the advancedSkillChar1 or advancedSkillChar2 isn't one of the ones in the fields. As for why you're getting duplicates, find this function in your copy of TAS, it's on line 314 of the original source:     applyQueuedUpdates = function() {       setAttrs(queuedUpdates);       queuedUpdates = {};     }, Change it to this:     applyQueuedUpdates = function() { log(queuedUpdates);       setAttrs(queuedUpdates);       queuedUpdates = {};     }, Then try your code again and see what you get written to the log as the queuedUpdates and post that back here.
1507735417
PadRpg
Sheet Author
API Scripter
I've got that:  {repeating_advancedSkills_-kwb0dpxthoa8rav9glm_advancedSkillBase: 11, repeating_advancedSkills_-kwb0dpxthoa8rav9glm_advancedSkill: 11}
1507735702
The Aaron
Pro
API Scripter
Ok.  That's the structure that gets sent to Roll20 via setAttrs().  It's obviously not duplicated.  You said that both rows get removed when you delete one of them?  Can you create the circumstance where you have 2 rows again and inspect the HTML and find the row ids of each?  I'm wondering if they are the same, or possibly only vary by capitalization.
1507736024
PadRpg
Sheet Author
API Scripter
Yes, both rows are removed when I delete one. Here's what I've got: (I think you're right about capitalization)
1507736391
The Aaron
Pro
API Scripter
Kind of figured that would be the case.  This is definitely a bug in the Roll20 backend.  You'd get the same results by doing the setAttr() call manually with the above data.  Probably will need to move this to Bugs.  Can you post a minimal repeatable case, probably as a couple of gist links?
1507736498
The Aaron
Pro
API Scripter
I'm curious if this is a recent change, I don't think I've seen this behavior before now.
1507737035
PadRpg
Sheet Author
API Scripter
Thanks for your help. I create a post in the Bug section if you want to follow it:&nbsp;<a href="https://app.roll20.net/forum/post/5632441/sheet-worker-new-line-in-error-in-my-repeating-sections" rel="nofollow">https://app.roll20.net/forum/post/5632441/sheet-worker-new-line-in-error-in-my-repeating-sections</a>
1507888922
PadRpg
Sheet Author
API Scripter
Aaron, FYI, when I'm not using your script, it works :'( &nbsp; &nbsp; &nbsp; &nbsp; on("change:repeating_advancedskills:advancedSkillChar1 change:repeating_advancedskills:advancedSkillChar2 change:repeating_advancedskills:advancedSkillMod", function(){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getAttrs([ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "repeating_advancedskills_advancedSkillChar1", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "repeating_advancedskills_advancedSkillChar2", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "repeating_advancedskills_advancedSkillMod",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "str", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "con", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "dex", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "siz", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "int", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "pow", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "cha" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ], function (values) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var modVal=parseInt(values.repeating_advancedskills_advancedSkillMod); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var charVal1=parseInt(values[values.repeating_advancedskills_advancedSkillChar1])||0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var charVal2=parseInt(values[values.repeating_advancedskills_advancedSkillChar2])||0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'repeating_advancedskills_advancedSkillBase': charVal1 + charVal2, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'repeating_advancedskills_advancedSkill':charVal1 + charVal2 + modVal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
1507898868
The Aaron
Pro
API Scripter
This is following a slightly different code path, it seems to be using an implied rowid to change only a single row, rather than iterating over all rows to change 1 or more rows.&nbsp; That's good info and should help with tracking down the iteration issue.