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

Change events happen four times with new 5e character sheet?

I've been trying to set up some notifications and other events around changing HP in a new script, and I've noticed that with the 5e Re-Shaped sheet a token change event seems to fire four times each time a user actually changes the value.  Example code: on('change:graphic:bar1_value', function (token, prev) { if(token.get('bar1_value') == 0 && prev.bar1_value > 0) { sendChat("Death","OH, THAT WAS UNFORTUNATE."); } }); In my game using the official 5e Re-Shaped sheet, if I select a PC token and change its HP to 0, I will see the message four times. This means not only is it registering 4 change events, it is also doing so 4 times simultaneously since prev still thinks HP == 0.  Anyone have any thoughts on a) what might be going on or b) how I can limit notifications to just one?
You probably have four of those tokens in your campaign on various maps and each one is having its bar value changed.
1469927464
The Aaron
Pro
API Scripter
Do you have 4 tokens that represent that character?  You could create a notification function wrapped in _.debounce() so that the message only happens once per group of notifications. 
Ah, yes, I do! I figured the copies of a token would be treated as instances of a single data object, didn't realize it was treating each one as a unique change event when they sync. I'll try debounce() and see how it goes!
1470106872
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Could also do some gating based on the playerpageid and Player specific pages attributes of Campaign()
1470162770

Edited 1470163254
EepMoody
API Scripter
_.debounce() ended up being the right fix, once I realized the examples I found were for lodash instead of underscore... d'oh!