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 .
×
Stuck in a login loop? Try manually signing out and back in before launching your game. Otherwise, contact the Help Center!
Create a free account

API setWithWorker() not triggering if a repeating section attr name contains a capital.

1620252916

Edited 1620257031
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
I made a demo to track down and demonstrate the problem. Here is the html file.  <!DOCTYPE html> <meta charset="UTF-8"> <div> <input name="attr_single" type="number" value="10"/> <input name="attr_Cap" type="number" value="20"/> <button name="roll_btn" type="roll" value="!demo @{character_id}"> </button> <fieldset class="repeating_demo"> <input name="attr_lower" type="number" value="30" > <input name="attr_Capital" type="number" value="40" > </fieldset> </div> <script type="text/worker"> on("change:single change:cap change:repeating_demo", function test1( eventInfo ) { 'use strict'; log( "Triggered test 1"); log( JSON.stringify(eventInfo)); }); // This is for test1 on("change:single change:cap change:repeating_demo:lower change:repeating_demo:capital", function test2( eventInfo ) { 'use strict'; log( "Triggered test 2"); log( JSON.stringify(eventInfo)); }); </script> and here is a .js file on("chat:message", function(msg) { 'use strict'; if(msg.type === "api" ) { // Expected input !demo @(selected|character_id} if ( msg.content.startsWith( "!demo" )) { log(msg); let ssa = msg.content.split( " " ); if( ssa.length < 2 ) {log("need charID: " + msg.content); return; } let attributes = findObjs({ _type: "attribute", _characterid: ssa[ 1 ] }); _.each( attributes, function (att) { log( "Found " + att.get("name") + " value: " + att.get("current")); att.setWithWorker( "current", parseInt(att.get("current")) + 1); }); // End for each attribute. } } // End if msgtype is api // End ON Chat:message. }); Sample results {"content":"!demo -MZySOqGyh_C_XUqjp3V","playerid":"-MZo_2oWEHuhkIoue7SQ","type":"api","who":"Chris D. (GM)"} "Found single value: 13" "Found Cap value: 23" "Found repeating_demo_-MZySW4KbPLes1C22Fbf_lower value: 33" "Found repeating_demo_-MZySW4KbPLes1C22Fbf_Capital value: 43" "Triggered test 1" "{\"sourceAttribute\":\"single\",\"sourceType\":\"api\",\"triggerName\":\"single\"}" "Triggered test 2" "{\"sourceAttribute\":\"single\",\"sourceType\":\"api\",\"triggerName\":\"single\"}" "Triggered test 1" "{\"sourceAttribute\":\"Cap\",\"sourceType\":\"api\",\"triggerName\":\"cap\"}" "Triggered test 2" "{\"sourceAttribute\":\"Cap\",\"sourceType\":\"api\",\"triggerName\":\"cap\"}" "Triggered test 1" "{\"sourceAttribute\":\"repeating_demo_-MZySW4KbPLes1C22Fbf_lower\",\"sourceType\":\"api\",\"triggerName\":\"repeating_demo_-mzysw4kbples1c22fbf\"}" "Triggered test 2" "{\"sourceAttribute\":\"repeating_demo_-MZySW4KbPLes1C22Fbf_lower\",\"sourceType\":\"api\",\"triggerName\":\"repeating_demo_-mzysw4kbples1c22fbf_lower\"}" "Triggered test 1" "{\"sourceAttribute\":\"repeating_demo_-MZySW4KbPLes1C22Fbf_Capital\",\"sourceType\":\"api\",\"triggerName\":\"repeating_demo_-mzysw4kbples1c22fbf\"}" So what this .js does it it looks for ALL attributes and increments them by one using setWithWorker().  So to use this demo, load it up in a sandbox.  Make a brand new character, that does not have any legacy attributes (important). If you want you can put your browser into developer tools console to verify that when the user changes the values, the sheetworkers trigger and write their logs.  Add one line to the repeating section, and change all of the values manually, so that the values exist in the database. Press the button. Look in the API console log and note that routine test1 triggered 4 times, once for each attribute.  Note that routine test2 only triggered 3 times, as it did not trigger for  sourceAttribute\":\"repeating_demo_-MZySW4KbPLes1C22Fbf_Capital Note that test2 did trigger for Cap but did not trigger for repeating_demo:Capital (code of course has it all lowercase in the on change event) So it triggers if the user changes it manually. The very specific bug is when the API uses setWithWorker() to trigger an attribute inside a repeating section that has a capital letter in it's name.   (Latest windows version, Chrome browser, no extension or cache issues.  Note: simply not using capitals is no longer a viable option, this is an old sheet that was started over a year before the suggestion  was added to the sheet author documentation that attributes not use capitals. And my naming scheme is that (for example) everything in repeating_section_talents has a name that starts with T_  and everything in skills starts with SK_. Now I kind of wish I had changed it 5 years ago, but I don't really see it as an option now.   I would greatly appreciate it this could get fixed.   Thanks. 
1621552490
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Bump.  This bug report clearly demonstrates a bug, and includes full routines to replicate the bug. 
1621579758
vÍnce
Pro
Sheet Author
Double Bump.