We use Cookies to help personalize and improve Roll20. For more information on our use of non-essential Cookies, visit our Privacy Policy here.
Accept
Advertisement Create a free account

on add token triggering on sandbox spin up.

1487102197
DXWarlock
Pro
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
Brian
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
Pro
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)