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:character" How to bind after the ready event has fired.

1454289488
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
<a href="https://wiki.roll20.net/API:Events" rel="nofollow">https://wiki.roll20.net/API:Events</a> &nbsp;says&nbsp; if you bind to add events (such as add:graphic ) before the ready event fires, you will receive add events for objects that were already present in the campaign. So my question is basically just to double-check my solution for binding after the ready event fires.&nbsp; My code used to have two ON events on("ready", function() { ... } and on("chat:message", function(msg) { .... ) Now when I added an&nbsp; on("add:character", function( obj ) { ... } right out in the open with the other two, it would fire once for every character in the campaign before the ready event fired. So I am uncertain how to "bind after the ready event fires. Am I supposed to make the new on statement a part of the ready event? on("ready", function() { ... on("add:character", function( obj ) { ... } } on("chat:message", function(msg) { .... ) It seems to work when I do it this way, it only fires when I add a brand new character.&nbsp; But is this a good idea? Is this how I am supposed to do it? It seems weird and dodgy to me. Thanks!
1454290567
The Aaron
Pro
API Scripter
No, that's exactly right. &nbsp;I bind all my events in the on('ready',function(){});
1454291655
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Thanks!