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

[DEV][Sheetworker] setAttrs silent:true not working in dev last few days?

1461177165
chris b.
Pro
Sheet Author
API Scripter
I think the silent option is not working in dev. I noticed it starting maybe last week when Riley fixed the "cannot delete old ID repeating row" bug. Here is my code (I also noticed it in other places, but this is the simplest): <span><label >Recalculate hit points and set hit points to max</label> <input type="checkbox" name="attr_HP_reset" value="1" /></span> on("change:HP_reset",    TAS.callback(function eventResetHP(eventInfo) { getAttrs(["HP_reset"],function(v){ TAS.debug("caught " + eventInfo.sourceAttribute + " event: " + eventInfo.sourceType + ", val is:"+ v["HP_reset"]  ); if (eventInfo.sourceType === "player" ) { PFSheet.updateMaxHP(true); PFSheet.updateTempMaxHP(true); setAttrs({"HP_reset":"0"},{silent:true}); } });     })  ); and here is the console output. As you can see the change:HP_reset is called a second time. The second time it has the new value of 0 that I just set. note even the "caught hp event: sheetworker" below, is an update the "HP" attribute, which also was done with {silent:true} yet it is still firing events on our sheet.  Really updating character sheet values app.js?1460651081:37 Setting up repeating sections took until 17ms app.js?1460651081:37 Finding list of dirty attributes took until 17ms sheetsandboxworker.js?20150218:56 Triggering for change:hp_reset VM41:178  TAS:  Entering: eventResetHP  VM41:178  TAS:  Exiting: eventResetHP  sheetsandboxworker.js?20150218:56 Triggering for change:hp_reset_max app.js?1460651081:37 Querytest took until 20ms app.js?1460651081:37 Set values took until 29ms app.js?1460651081:37 Took 74ms VM41:178  DEBUG:  caught hp_reset event: player, val is:1  app.js?1460651081:37 Really updating character sheet values app.js?1460651081:37 Setting up repeating sections took until 18ms app.js?1460651081:37 Finding list of dirty attributes took until 18ms sheetsandboxworker.js?20150218:56 Triggering for change:hp_reset VM41:178  TAS:  Entering: eventResetHP  VM41:178  TAS:  Exiting: eventResetHP  sheetsandboxworker.js?20150218:56 Triggering for change:hp_reset_max sheetsandboxworker.js?20150218:56 Triggering for change:hp VM41:178  TAS:  Entering: eventUpdateHP  VM41:178  DEBUG:  caught hp event: sheetworker  VM41:178  TAS:  Exiting: eventUpdateHP  sheetsandboxworker.js?20150218:56 Triggering for change:hp_max app.js?1460651081:37 Querytest took until 20ms app.js?1460651081:37 Set values took until 30ms app.js?1460651081:37 Took 73ms VM41:178  DEBUG:  caught hp_reset event: sheetworker, val is:0  app.js?1460651081:37 Really updating character sheet values app.js?1460651081:37 Setting up repeating sections took until 16ms app.js?1460651081:37 Finding list of dirty attributes took until 16ms app.js?1460651081:37 Querytest took until 19ms app.js?1460651081:37 Set values took until 31ms app.js?1460651081:37 Took 92ms
1461178495

Edited 1461178600
chris b.
Pro
Sheet Author
API Scripter
Pretty sure this is it since code that has worked for months is going haywire in dev, and looking at the logs i see lots of events fired where sourceType is "sheetworker" where they were not firing before. Wrapping most of my eventHandlers in a check for Player fixes most of the issues, but not all (since sometimes both are valid scenarios), 
1461185036

Edited 1461185276
chris b.
Pro
Sheet Author
API Scripter
Also: after adding a ton of checks for eventInfo.sourceType, it helped eliminate loops. BUT, I never did that before since I relied on good design to not create loops in the first place. sigh, now my code looks silly. Also this breaks a lot of work we put in to update fields that rely on other fields directly in javascript, rather than setting a value, then reading in the event and updating the second field. I had to comment those shortcuts out and am back to relying on the event engine. I guess either way is a valid design but would like silent:true to work again.
1461263511
Phil B.
Forum Champion
Sheet Author
I just tested this on dev and it seems to be working as intended for me. If you scripts are pretty complicated, which I'm thinking they are, there might be something else that's changing that is cascading unexpectedly. Here's everything I used to test: Control Case, without {silent: true} <span><label >Recalculate hit points and set hit points to max</label> <input type="checkbox" name="attr_HP_reset" value="1"  /></span> <script type="text/worker"> on("change:HP_reset", function(eventInfo) {     console.log('HP_Reset');     getAttrs(["HP_reset"],function(v){     setAttrs({"HP_reset":"0"}); }); }); </script> CLICKED app.js?1460651081:37 Really updating character sheet values app.js?1460651081:37 Setting up repeating sections took until 1ms app.js?1460651081:37 Finding list of dirty attributes took until 1ms sheetsandboxworker.js?20150218:56 Triggering for change:hp_reset app.js?1460651081:37 Querytest took until 2ms VM41:3 HP_Reset // FIRST CHANGE sheetsandboxworker.js?20150218:56 Triggering for change:hp_reset_max app.js?1460651081:37 Set values took until 3ms app.js?1460651081:37 Took 4ms app.js?1460651081:37 Really updating character sheet values app.js?1460651081:37 Setting up repeating sections took until 0ms app.js?1460651081:37 Finding list of dirty attributes took until 0ms app.js?1460651081:37 Querytest took until 1ms sheetsandboxworker.js?20150218:56 Triggering for change:hp_reset VM41:3 HP_Reset // RESPONDING TO ITS OWN CHANGE, CHANGING 0 TO 0 SO NO MORE "CHANGE" TRIGGERS sheetsandboxworker.js?20150218:56 Triggering for change:hp_reset_max app.js?1460651081:37 Set values took until 2ms app.js?1460651081:37 Took 3ms Test Case, with {silent: true} <span><label >Recalculate hit points and set hit points to max</label> <input type="checkbox" name="attr_HP_reset" value="1"  /></span> <script type="text/worker"> on("change:HP_reset", function(eventInfo) {     console.log('HP_Reset');     getAttrs(["HP_reset"],function(v){     setAttrs({"HP_reset":"0"}, {silent: true}); }); }); </script> CLICKED app.js?1460651081:37 Really updating character sheet values app.js?1460651081:37 Setting up repeating sections took until 4ms app.js?1460651081:37 Finding list of dirty attributes took until 4ms app.js?1460651081:37 Querytest took until 8ms sheetsandboxworker.js?20150218:56 Triggering for change:hp_reset VM41:3 HP_Reset // ONLY HAPPENS 1 TIME app.js?1460651081:37 Set values took until 10ms app.js?1460651081:37 Took 12ms sheetsandboxworker.js?20150218:56 Triggering for change:hp_reset_max app.js?1460651081:37 Really updating character sheet values app.js?1460651081:37 Setting up repeating sections took until 1ms app.js?1460651081:37 Finding list of dirty attributes took until 1ms app.js?1460651081:37 Querytest took until 1ms app.js?1460651081:37 Set values took until 2ms app.js?1460651081:37 Took 3ms
1461265599
chris b.
Pro
Sheet Author
API Scripter
ok you are right, sorry, i made an even simpler test and it is not firing  It's just on the Pathfinder sheet this was not happening before, so I'm not sure what's going on. I know we have some attributes that reference others and we rely on the autocalculating system to fire events for us, maybe those are what is causing the behavior i'm seeing.  But i'm getting most of it ironed out by just checking eventInfo.sourceType.