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

on add token triggering on sandbox spin up.

1487102197
DXWarlock
Sheet Author
API Scripter
Not sure if a bug, or a misunderstanding of why it triggers. But the below code will log every single token I have on any page when I save the sandbox. on('add:token', function(obj) {     log(obj); }); Shouldn't this only trigger when a token is drug to the table(or created) as a new object on the page? I'm trying to call an event anytime a character token is drug to a page for the first time. But its triggering on every token already existing on all pages on API startup.
1487117272
Lithl
Pro
Sheet Author
API Scripter
This is expected behavior. If you want to only trigger the add:token even when a new token is created, register the event handler after the VTT is loaded (ie, inside of a ready event handler): on('add:token', function(obj) { // triggers for each existing token, and for new tokens }); on('ready', function() { on('add:token', function(obj) { // triggers for new tokens only }); });
1487123715
DXWarlock
Sheet Author
API Scripter
Ah OK thanks! Was driving me mad (along with applying changes to ALL the tokens i had out on pages..should have tested before blindly doing token changes lol)