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 setAttrs only updating the last value in a list in routine called with setWithWorkers()

1634331033
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
I have one particular routine that is doing weird stuff and I have no idea why.  It has a variable named vals that has some name/value combinations. I call setAttrs, and ONLY THE LAST VALUE gets set.  I do the exact same thing in dozens of other routines, but this one has problems for some reason.  The only two things I can think of that might be involved is : (1) It is a sheetworker that is being run on the roll20 servers. (2) Some of the names contain capital letters.  Specifically There is an api that calls setWithWorders() to set a value which causes the Roll20 servers (instead of a users local machine) to run the sheetworker. The results of logs end up in the API console log instead of a users machines development tools console log. This is a very old sheet that was started years before Roll20 explicitly said to not use capitals in names. These two issues actually sometimes makes a difference.  For example I know that if a variable name inside a repeating section has a capital, then the on change events will not trigger on  the roll20 servers even though it will on a users machine. I don't know if ether or both of these issues are involved in this problem. It is just the only two things that might.  Anyway, here is what happens.  let vals={}; ... if(entry.movebased) vals[pre+"MoveBased"]=entry.movebased; if(entry.visionbased) vals[pre+"VisionBased"]=entry.visionbased; log(JSON.stringify( vals )); setAttrs(vals); If this code is triggered manually on a user machine, it works fine.  But when triggered via a setWithWorkers call, then only the very last one (VisionBased) will be set. None of the others will be.  The log files on the values about to be written seem normal.  "{\"repeating_talents_-Mlze- jRxrnMDqIJS1Bu_T_Mod-Type\":\" Action\",\"repeating_talents_- Mlze-jRxrnMDqIJS1Bu_T_Target\" :\"MD1: @{target|Target|token_id}\", \"repeating_talents_-Mlze- jRxrnMDqIJS1Bu_T_Defensive\":\ "1\",\"repeating_talents_- Mlze-jRxrnMDqIJS1Bu_T_ Resistance\":\"0\", \"repeating_talents_-Mlze- jRxrnMDqIJS1Bu_T_MoveBased\":\ "1\",\"repeating_talents_- Mlze-jRxrnMDqIJS1Bu_T_ VisionBased\":\"1\"}" Note that both VisionBased and MoveBased look identical and both should have values of 1.  If I run an Inspect special function I wrote I get... (From Inspect to player ):  name: repeating_talents_-Mlze- jRxrnMDqIJS1Bu_T_MoveBased current: _id: -Mlze0kthkh7mLFOuwrw (From Inspect to player ):  name: repeating_talents_-Mlze- jRxrnMDqIJS1Bu_T_VisionBased current: 1 _id: -Mlze0kuKCL4h_vnHrzW note that VisionBased has a current value of 1, but MoveBased has a current value of blank or undefined.  To the best of my knowledge all other routines and setAttrs are working fine.  As a workaround, I rewrote the routine to instead of collecting 6 values in vals and then calling setAttrs once, I instead put one value at a time into vals and call setAttrs 6 times, and that works. But it still seems like something is very wrong here. 
1634663939
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
hey Chris, This looks like an issue where your code is doing one of two things: attempting to set an attribute to an illegal value (NaN, undefined, or null are the usual culprits). You aren't creating a new rowID for each iteration, so it adds each one to the setObj, but it's updating the same attribute each time Can you share the full iteration code?
1634688103
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
You can see the actual  values the system is attempting to set in the 2nd code block. As you can see it is attempting to set repeating_talents_-Mlze-jRxrnMDqIJS1Bu_T_MoveBased to "1". And then when we ask it to print the value stored in it a few minutes later it has nothing printable, probably an empty string since it does  not say undefined.  I am not sure what you mean by the full iteration code.    what?
1634694867

Edited 1634696372
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ah, I see what you're talking about. That certainly seems like a bug, and a big one at that. Doesn't matter if you use lowercase attribute names in your html or not, the API triggered sheetworker just seems unable to properly set repeating values. Simple reproduction code: <input type='checkbox' name='attr_trigger' value='1'> <fieldset class='repeating_test'> <input type='text' name='attr_receiver_1' value='' readonly> <input type='text' name='attr_receiver_2' value='' readonly> <input type='text' name='attr_receiver_3' value='' readonly> <input type='text' name='attr_receiver_4' value='' readonly> </fieldset> <script type='text/worker'> on('change:trigger',(event)=>{ console.table(event); let setObj = {}; const rowID = generateRowID().toLowerCase(); console.table({rowID}); [1,2,3,4].forEach((num)=>{ setObj[`repeating_test_${rowID}_receiver_${num}`] = `triggerValue: ${event.newValue}`; }); console.table(setObj); setAttrs(setObj,{silent:true}); }); </script> Used ChatSetAttr to do the API triggered change.
1635286506
Analyzer
Roll20 Team
Hello folks! Thanks for bringing this issue to our attention. A bug report has been filed with the Character Sheet Team and will be working on getting a fix. We appreciate your patience and will provide any updates when available.