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 .
×
May your rolls be chill this holiday season!
Create a free account

[Help] Player Join Event

Is there an event for when a player logs into a campaign?
1436587120
Lithl
Pro
Sheet Author
API Scripter
on('change:player:_online', function(obj, prev) { if (!obj.get('online')) return; // A player just logged in });
1436587287
The Aaron
Pro
API Scripter
I just want to add (because I don't think it is obvious) that the _ on _online is required in the on( <event>, ... ) context. The _ can (and should) be removed when calling .get() on an object, but is required in the context of an event.
Great! Thanks, guys!
1436587723
Lithl
Pro
Sheet Author
API Scripter
The Aaron said: The _ can (and should) be removed when calling .get() on an object, but is required in the context of an event. "Should" is really a matter of style, here. both .get('online') and .get('_online') will work, and the API server is making the check for the presence or absence of the _ (if necessary) regardless. (There was a bug/security hole many many many months ago which among other things allowed me to see the source for .get(), which has since been closed.)
1436590230
The Aaron
Pro
API Scripter
I say "should" because its omission allows the script to continue functioning in the event that a read-only property becomes read-write. Conceptually, the writability of a property should not be a consideration for .get()ing the value (get being a read operation), which is another reason to leave it off. Functionally, setting should fail in both cases, (again, the expected result), thus you will never see a set with that property listed to begin with. The only purpose it serves is then as a purely antiquated "Hungarian" notation meant to instruct the reader as to the nature of the property, which is better expressed by the error trying to set it would create, or by the documentation which already states "This is a read-only property." However, I allow for the possibility that you feel differently, as usual. =D
1436598613
Lithl
Pro
Sheet Author
API Scripter
It's a good point to make, and we have had properties that were previously read-only become writable, IIRC. I always omit the leading underscore from my get calls anyway, because I think it looks better. =P
Thanks for all the info. Very helpful!