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

Issue with ChatSetAttr and sheetworkers (particularly, attr_ that are checkboxes)

I am using 5e dnd Community Contributed sheet. I seen other forums that said this is a known bug but wanted to confirm if my specific case was applicable or not (to the bug I've seen on the forums)  So I have created a sheetworker that performs short and long rest mechanics on my "Class actions" and "Class Resources" (resets them to max/0 depending on which one) that checks "on(change:checkbox clicked:actionbutton){...} and it works fine off of my sheet, I even have an action button that also works off of the sheet.  my "Class Actions" are hard coded amount and indexed 1-20. my "Class Resources" are repeating_sections. For some strange reason.... when I use the following code API in a token action... (long_rest is the name of my checkbox attr, 1 = the value when checked) !setattr --mute --name Test Character --long_rest|1 My repeating_sections will work (meaning they will reset to the appropriate values) while my non-repeating sections (the "Class Actions") will not change. Also I have some console.log(); in my sheetworker as I am doing this and I notice that even though the repeating sections properly change from the token macro,(due to the fact that my repeating_sections are getting updated) the token macro does not cause the console.log code in the sheetworker to goto the console.... It only shows the console.log() commands if i click the checkbox on the sheet or press the button on the sheet. Even though my token macro is changing the same checkbox variable. (as a Side note, my sheetworker changes the checkbox back to 0 once execution is done) I didn't know if anyone had notice this behavior difference between repeating_sections and non-repeating section which is why I thought it important to mention it here. I tried to make my Checkboxes value = "hidden_attr" and have my API change the hidden value but that didn't work either. I can provide code if someone wants but didn't want to just post everything as i feel snippets of code are easier to look through :)
1593318386
GiGs
Pro
Sheet Author
API Scripter
There is (or was, it may have been fixed) a bug in sheet workers when triggered by the API, but it was a very specific bug and wouldnt cause the effect youre describing. The fact your repeating sections and non repeating attributes are behaving different points very strongly to the issue being something in your code. There is no difference between them as far as the API and sheet workers are concerned, except in the way you have to access repeating attributes. I dont follow what you mean here: I tried to make my Checkboxes value = "hidden_attr" and have my API change the hidden value but that didn't work either. It's not going to be possible to diagnose this without seeing code. But no need to post it all. We just need to see the html for any attributes directly involved in this, and the sheet worker code itself.
Just want to reclarify, that my character sheet works for both repeating_sections and non-repeating_sections and outputs the console commands. while the API/Token Macro will update the repeating_sections and nothing else.... I have a TL;DR at the bottom that summarizes the situation. Anyway here is the code. so far <div class="sheet-row"> <div class="sheet-col-1-12 sheet-classaction-row-number sheet-margin-top">1</div> <div class="sheet-col-1-4"> <input type="text" name="attr_classactionname1"> </div> <div class="sheet-col-1-12"> <input type="number" name="attr_classactionresource1" value="1" min="0" /> </div> <div class="sheet-col-1-12"> <input type="number" name="attr_classactionresource1_max" value="1" /> </div> <div class="sheet-col-1-6"> <select name="attr_classactionrecharge1"> <option value="None">None</option> <option value="Short Rest">Short Rest</option> <option value="Long rest">Long Rest</option> <option value="Other">Other</option> </select> </div> <div class="sheet-col-1-6"> <select name="attr_classactionsource1"> <option value="Not set" selected="selected">---</option> <option value="Artificer">Artificer</option> <option value="Barbarian">Barbarian</option> <option value="Bard">Bard</option> <option value="Cleric">Cleric</option> <option value="Druid">Druid</option> <option value="Fighter">Fighter</option> <option value="Monk">Monk</option> <option value="Paladin">Paladin</option> <option value="Ranger">Ranger</option> <option value="Rogue">Rogue</option> <option value="Sorcerer">Sorcerer</option> <option value="Warlock">Warlock</option> <option value="Wizard">Wizard</option> <option value="Feat">Feat</option> <option value="Other">Other</option> </select> </div> <div class="sheet-col-1-6 sheet-center"> <button type='roll' class="sheet-roll" name="roll_classaction1" value="&{template:5eDefault} {{title=@{classactionname1}}} {{subheader=@{character_name}}} {{subheaderright=Class/Racial/Other ability}} {{freetextname=@{classactionname1}}} {{freetext=@{classactionoutput1}}}">Use</button> </div> </div> The Above is 1 of 20 segments that existed in the ClassAction section of the character sheet (I did not modify, this is how it was) The important attributes here are `attr_classactionrecharge${#}` and `attr_classactionresource${#}` as those are those the only ones I bother to check and change.. Again my checkbox/button on my character sheet does update these when pressed/checked. Below is my action buttons for the long rests and short rests <div class="sheet-row"> <div class="sheet-col-4-5 sheet-center sheet-small-label sheet-sub-header sheet-padl sheet-padr">Short & Long Rests</div> <div class="sheet-row"> <div class="sheet-col-2-5 sheet-padl sheet-align-left sheet-padr"> <input type="hidden" name ="attr_hidden_short_rest" value="1"/> <input type="checkbox" name="attr_short_rest" value="1"/> <button type="action" name="act_actionshortrest" title="Click me to take a Short Rest!"><span style="font-family: fontello"></span>:Take Short Rest?</button> </div> <div class="sheet-col-2-5 sheet padl sheet-align-right sheet-padr"> <input type="hidden" name ="attr_hidden_long_rest" value="1"/> <input type="checkbox" name="attr_long_rest" value="1"/> <button type="action" name="act_actionlongrest" title="Click me to take a Long Rest!"><span style="font-family: fontello">:</span>Take Long Rest?</button> </div> </div> </div> Again my sheetworker likes the above code as long as i click the checkbox/button from the character sheet. Below is the repeating_section that I also check <fieldset class="repeating_classresources"> <div class="sheet-row"> <div class="sheet-col-5-12"> <input type="text" name="attr_ClassResourceName" /> </div> <div class="sheet-col-1-4"> <select name="attr_ClassResourceRecharge"> <option value="None">None</option> <option value="Short Rest">Short Rest</option> <option value="Long Rest">Long Rest</option> <option value="Other">Other</option> </select> </div> <div class="sheet-col-1-6"> <input type="number" name="attr_ClassResourceTotal" value="1" min="0" step="1" /> </div> <div class="sheet-col-1-6"> <input type="number" name="attr_ClassResourceTotal_max" value="1" min="0" step="1" /> </div> </div> </fieldset> Above will be updated from the API/token macro and the sheet buttons works great. Below is API/Token Macro that I call to test to see if it works... !setattr --mute --name Test Character --long_rest|1 And... !setattr --mute --name Test Character --short_rest|1 Below is my Sheetworker, You may recognize it GiGs as you helped trouble shoot it originally :)  I was able to get it to work with the other sections eventually.... (atleast from the original checkbox/action button on my sheet) Also I try to do .toLowerCase on the parts below that were in the for loop but kept getting type error so decided to abandon that for now (my strings are from a strict dropdown so they should all be the same atleast) <== not important or relevant to my concern however. on(`change:long_rest clicked:actionlongrest`, function (eventinfo) { //Section of repeating to be checking let section = "classresources"; //get proper id for repeating sections (repeating_classresources_) getSectionIDs(`repeating_${section}`, function (idArray) { let fields = ["ClassResourceName", "ClassResourceRecharge", "ClassResourceTotal", "ClassResourceTotal_max"]; const attrArray = idArray.reduce( (m,id) => [...m, ...(fields.map(field => `repeating_${section}_${id}_${field}`))],[]); let attrActionArray = []; //console.log(`====== attrArray: ${attrArray.join(', ')}`); for(let i = 1;i < 21; i++){ attrActionArray.push(`classactionname${i}`,`classactionrecharge${i}`,`classactionresource${i}`,`classactionresource${i}_max`); } //console.log(`====== attrArray: ${attrArray.join(', ')}`); //console.log(`====== idArray: ${idArray.join(', ')}`); let CombinedAttrArray = [...attrArray,...attrActionArray]; //console.log(`====== CombinedAttrArray: ${CombinedAttrArray.join(', ')}`); getAttrs(CombinedAttrArray, function (values) { const setattrobj = {}; //console.log(`===== values: ${JSON.stringify(values)}`); idArray.forEach(id =>{ const recharge = values[`repeating_classresources_${id}_ClassResourceRecharge`]; //console.log(`==== id: ${id}; recharge: ${recharge}`); //check if ClassResourceRecharge has been set to the string "Short Rest" (this attr is set with a dropdown) // a common source of errors is having mismatched cases, so here we ensure they are both the same case. if(recharge.toLowerCase() === "long rest" || recharge.toLowerCase() === "short rest" ){ const max = parseInt(values[`repeating_classresources_${id}_ClassResourceTotal_max`])||0; //console.log(`==== id: ${id}; max: ${max}`); setattrobj[`repeating_classresources_${id}_ClassResourceTotal`] = max; } }); for(let i = 1; i < 21; i++){ if(values[`classactionrecharge${i}`] === "Long rest" || values[`classactionrecharge${i}`] === "Short Rest"){ setattrobj[`classactionresource${i}`] = 0; } } //check if empty or not console.log(`=== values: ${JSON.stringify(values)}`); console.log(`=== setattrobj: ${JSON.stringify(setattrobj)}`); // add short_rest here so that it gets updated along with the rest. setattrobj.long_rest = 0; // since setattrobj will now always contain something, no need for the if statement setAttrs(setattrobj); }); }); }); on(`change:short_rest clicked:actionshortrest`, function (eventinfo) { //Section of repeating to be checking let section = "classresources"; //get proper id for repeating sections (repeating_classresources_) getSectionIDs(`repeating_${section}`, function (idArray) { let fields = ["ClassResourceName", "ClassResourceRecharge", "ClassResourceTotal", "ClassResourceTotal_max"]; const attrArray = idArray.reduce( (m,id) => [...m, ...(fields.map(field => `repeating_${section}_${id}_${field}`))],[]); let attrActionArray = []; for(let i = 1;i < 21; i++){ attrActionArray.push(`classactionname${i}`,`classactionrecharge${i}`,`classactionresource${i}`,`classactionresource${i}_max`); } const CombinedAttrArray = [...attrArray,...attrActionArray]; //console.log(`====== attrArray: ${attrArray.join(', ')}`); //console.log(`====== idArray: ${idArray.join(', ')}`); //console.log(`====== CombinedAttrArray: ${CombinedAttrArray.join(', ')}`); getAttrs(CombinedAttrArray, function (values) { const setattrobj = {}; //console.log(`===== values: ${JSON.stringify(values)}`); idArray.forEach(id =>{ const recharge = values[`repeating_classresources_${id}_ClassResourceRecharge`]; //console.log(`==== id: ${id}; recharge: ${recharge}`); //check if ClassResourceRecharge has been set to the string "Short Rest" (this attr is set with a dropdown) // a common source of errors is having mismatched cases, so here we ensure they are both the same case. if(recharge.toLowerCase() === "short rest" ){ const max = parseInt(values[`repeating_classresources_${id}_ClassResourceTotal_max`])||0; //console.log(`==== id: ${id}; max: ${max}`); setattrobj[`repeating_classresources_${id}_ClassResourceTotal`] = max; } }); for(let i = 1; i < 21; i++){ if(values[`classactionrecharge${i}`] === "Short Rest"){ setattrobj[`classactionresource${i}`] = 0; } } //che //check if empty or not console.log(`=== values: ${JSON.stringify(values)}`); console.log(`=== setattrobj: ${JSON.stringify(setattrobj)}`); // add short_rest here so that it gets updated along with the rest. setattrobj.short_rest = 0; // since setattrobj will now always contain something, no need for the if statement setAttrs(setattrobj); }); }); }); Below is the console.log(); when i click the checkbox/action button (for long_rest, also activates short_rest mechanics too).. The repeating_sections should be set to numbers while the non-repeating_sections should be set to 0 (as repeating is set to "current" while non repeating is set to "Used", might change in the future but that's a minor fix for now) === setattrobj: {"repeating_classresources_-maryrmz3mlkngqkppu7_ClassResourceTotal":8,"repeating_classresources_-maryv-qmyllwt0kjtc8_ClassResourceTotal":12,"repeating_classresources_-marywotav2skxc5fcmt_ClassResourceTotal":9,"repeating_classresources_-maryygafgvhwkxmkp1r_ClassResourceTotal":17,"classactionresource1":0,"classactionresource2":0,"classactionresource3":0,"classactionresource4":0} Again the biggest/weirdest part is that the API/Token will change my character sheet for the repeating_section, but it doesn't output the console.log(); when using the API/token macro and it doesn't update the non-repeating_sections tl;dr Use API/Token macro (API is ChatSetAttr) long_rest or short_rest repeating_section resources DO update correctly. Console.log() that exists in the sheetworkers DO NOT get called/execute non-repeating_section resources DO NOT update Use Character sheet checkbox/action button for long_rest or short_rest repeating_sections resources DO update correctly. Console.log() that exists in the sheetworkers DO get called/execute non-repeating_section resources DO update.
1593321614
GiGs
Pro
Sheet Author
API Scripter
Thats very comprehensive. I'll have a look through it tomorrow. Can you give a couple of specific attribute names that do not update?
1593321991

Edited 1593323748
Sure If you look at the "====setattrobj Console.log()" code above its the 4 non-repeating_sections {classactionresource1, classactionresource2, classactionresource3, classactionresource4}. None of them reset to 0 if I use the API/macro, while they WILL update if I use the character sheet actionbutton/checkbox. The above Console log happens when I click the action button/checkbox on the character sheet. Those listed are the values they should be set to ("0"). They do not reset to "0" when I try through ChatSetAttr/Token Macro.  My Character's name is "Test Character" without the quotes just for completeness. EDIT:Also the only other API's I have downloaded are "Short Rest", "5th Edition OGL by Roll20 Companion", "5e Shaped Companion Script" (disabled because gives me error code in API if i don't) and "ChatSetAttr". I am only using the "ChatSetAttr" API, other were just there for reference so I could see how they chose to implement similar ideas and gain more API/Script knowledge :) Made a separate game that is using the Original 5e DND Community Contributed sheet and wanted to test this sheet before trying to load it live into my actual game. EDIT2: Also point out that I have made the "classactionrecharge1" and "classactionrecharge2" equal to "Short Rest" and "classactionrecharge3" and "classactionrecharge4" equal to "Long rest" (again I notice the inconsistency here but that's what the sheet was originally and I haven't bothered to change it yet)
1593565063
GiGs
Pro
Sheet Author
API Scripter
I forgot about this thread. Have you solved the issue? I dont see anything obvious that would be causing this issue. If it's still an issue, can you post the entire sheet (HTML and CSS) to pastebin or gist, and I'll try to find time to test it.
I finally created a Gisthub account. Thanks for twisting my arm :) . Just been&nbsp;forced&nbsp;to opening the character sheet and pressing the button, its a small price to pay but it does indeed reset the resource the way I want them too. Just can't get the ChatSetAttr API command in a token macro to do the same thing (with the checkbox)&nbsp; I posted secret and here is the link to the HTML:&nbsp; <a href="https://gist.github.com/OGTatarius/03675db5d1fa468dda71143fffe24cf2" rel="nofollow">https://gist.github.com/OGTatarius/03675db5d1fa468dda71143fffe24cf2</a> Here is the CSS of my Code:&nbsp; <a href="https://gist.github.com/OGTatarius/ff0f380afa15cc19a4ef095271075fec" rel="nofollow">https://gist.github.com/OGTatarius/ff0f380afa15cc19a4ef095271075fec</a> Let me know if you need anything else from me.&nbsp; as a Recap of the situation above Use API/Token macro (API is ChatSetAttr) long_rest or short_rest is the name of the attribute that activates the sheetworker (along with act_actionlongrest and act_actionshortrest buttons) repeating_section resources DO update correctly. Console.log() that exists in the sheetworkers DO NOT get called/execute non-repeating_section resources DO NOT update Use Character sheet checkbox/action button for long_rest or short_rest repeating_sections resources DO update correctly. Console.log() that exists in the sheetworkers DO get called/execute non-repeating_section resources DO update.
1593574099

Edited 1593574193
GiGs
Pro
Sheet Author
API Scripter
I cant reproduce your issues. When I use chatSetAttr, it properly updates both groups of attributes. I have made no change to the code. There's a difference in the way they are updated: those inside the repeating section get reset to Used = 0, while those outside the repeating section get Current updated to equal the maximum. But both are being correctly updated. Try creating a different character, and work on that one. Maybe your "Test Character" has some corruption. Unrelated point: Those 20 class resource boxes would probably be better as a repeating section.
Thank you for looking at it. I will do by your example. Wasn't aware a character could specifically get corrupted so that's good to know..&nbsp; I am aware that those class features would be better suited for repeating sections, I plan to make that change eventually, however the original Sheet author had them that way. Would also like to make the range and melee weapon sections for each weapon a repeated sections, and the inventory, basically everywhere you can have a undetermined amount of things listed... seems good. I am fond of repeating sections :) reminds me of dynamically creating Arrays with (malloc!) functions in c programming.&nbsp; As a small side question did you do it as a token macro or typed the ChatSetAttr command directly into the chat window? just curious for my testing purposes... I am glad that what I was doing wasn't the cause of the bug it would seem :) Thank again for your time as always.
1593577659

Edited 1593577691
I'll be darned... it worked.&nbsp; I had already uploaded it into my game, not expecting to be able to use it (with the API) and it works for all my characters thus far.. Thanks! :) now to update spell slots under the same commands :P just need to pull those repeating sections and attributes as well.... I will probably also change the output format for the repeating_classresources section from "Current" to "Used" that way it resets to 0 like everything else. Consistancy in the character sheets makes them easier to read for players.(and doesn't have to worry about finding the "max" when setting the current value). The scariest and best bugs are the ones that "fix" themselves, but you don't understand/know why O.o
1593578318
GiGs
Pro
Sheet Author
API Scripter
The different Used/Current behaviour was confusing to me so I agree making them consistent is a good idea.
Unfortunately, I am getting weird behavior sometimes it works with the setChatAttr sometimes it doesn't (depends on what character) sometimes fails completely with setChatAttr(like not resetting even the repeating sections and not adjusting anything.... I even had it have the checkbox stuck on I am not good at console.log debugging but I notices when trying to trouble shoot that simply opening my players character sheets (using Alt double click) I get the follow console error (this happens regardless of doing anything... again my button and checkbox still work) TypeError: Cannot read property 'replace' of undefined at T.i.autoCalcFormula (app.js?1593531535:567) at app.js?1593531535:567 at NodeList.forEach (&lt;anonymous&gt;) at Function.C.each.C.forEach (base.js?1588774597:6) at T.i._updateSheetValues (app.js?1593531535:567) at r (base.js?1588774597:6) at nrWrapper ((index):14) And
1593583771
GiGs
Pro
Sheet Author
API Scripter
I havent seen that error, but that may be because I dont have any completed characters. I think&nbsp; that error message suggests there's a broken autocalc in the sheet. I did notice this error in the console: SHEET ERROR: Specified a disabled input without a valid formula in the value attribute. That is probably referring to the version line 44: &lt;input&nbsp;class="sheet-underlined&nbsp;sheet-center"&nbsp;type="text"&nbsp;name="attr_sheet_version"&nbsp;value="1.1.4"&nbsp;disabled="disabled"&nbsp;/&gt; That would be better a readonly &lt;input&nbsp;class="sheet-underlined&nbsp;sheet-center"&nbsp;type="text"&nbsp;name="attr_sheet_version"&nbsp;value="1.1.4"&nbsp;readonly&nbsp;/&gt; But that wont have anything to do with the error you described above. I notice you have your sheet popped out. Do you still have issues when the sheet isnt popped out?
Didn't think that would make a difference... On the same character i showed it still refuses to update that 2nd resource no matter what i do... The long rest checkbox didn't get stuck this time.... Although I think I found something that can be reproduced?&nbsp; It doesn't seem to like a resource that only has 1 as it max.... will not set current to max if max is only 1.... If you don't manually change the max from 1 (the default) it will never set the value with the API for that (although the button/manual checkbox will?) Once you change the value of max you can put it back to 1 and it works.... again weird Is there a reason for why ChatSetAttr would not like default values? I will look into my code more and see if I mess up a fringe case, this is the "repeating_section" variables btw.&nbsp; I will just manually use the character sheet button for now, that works no matter what, although again not sure why.... The image below is showing the above behavior i mentioned of not moving the max from it's default.... Also I reloaded the Regular character sheet (original 5e community contributed 5e character sheet) and that same "replace" console error shows up. I'll make a new game and make a character, something isn't set right&nbsp; I tried making that 1 line readonly and it still complained about that one console error you mentions (SHEET ERROR...) still didn't help.
1593587384
GiGs
Pro
Sheet Author
API Scripter
J.C &nbsp;said: It doesn't seem to like a resource that only has 1 as it max.... will not set current to max if max is only 1.... If you don't manually change the max from 1 (the default) it will never set the value with the API for that (although the button/manual checkbox will?) Once you change the value of max you can put it back to 1 and it works.... again weird Is there a reason for why ChatSetAttr would not like default values? Default values are different from attributes that have been set manually. I would think chatSetAttr can cope with that difference, but maybe it can't. There is definitely something to test there.&nbsp; Also I reloaded the Regular character sheet (original 5e community contributed 5e character sheet) and that same "replace" console error shows up. I'll make a new game and make a character, something isn't set right&nbsp; I tried making that 1 line readonly and it still complained about that one console error you mentions (SHEET ERROR...) still didn't help. It's probably not reporting that line then. i didnt look through all the lines with disabled in them, because there was a lot. I'd look through them and check if any have improperly constructed calculations.