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 .
×

Change Events Fired for API Created Path Objects

1597079513

Edited 1597088960
Hello, When creating path objects in the API it looks like a change event is being fired. Specifically it's firing the "change:path:_path" and "change:path" events. Path objects created in game with any of the rectangle, polygon, or freehand tools do not cause the change events to be fired and instead only fire "add:path" as expected. Edit:  Is this behavior a bug? As far as I know nothing else does this. It looks like path objects are created blank and then updated with the correct geometry which kind of feels like we should be able to change the geometry after creation ourselves? Test Code: "use strict" ; function displayEvents ( eventNames ) { for ( const eventName of eventNames ) { on ( eventName , function ( object , previous ) { const info = [ [ "Event Name" , eventName ], [ "Object Type" , object . get ( "_type" )], [ "Object Id" , object . id ] ]; if ( previous ) { for ( const key in previous ) { const oldValue = previous [ key ]; const newValue = object . get ( key ); if ( newValue != oldValue ) { info . push ([ `Old $ { key } ` , oldValue ], [ `New $ { key } ` , newValue ]); } } } info . forEach ( row => log ( row . join ( ": " ))); }); } } on ( "ready" , function main () { displayEvents ([ "add:path" , "change:path" , "change:path:_path" , "change:path:path" ]); createObj ( "path" , { _pageid : findObjs ({ _type : "page" })[ 0 ]. id , _path : `"[["M",0,0],["L",700,700]]"` , layer : "objects" , stroke : " #000000 " , top : 350 , left : 350 , width : 700 , height : 700 }); }); Console Output: Spinning up new sandbox... "Starting webworker script..." "Loading 710 translation strings to worker..." "Event Name: change:path:_path" "Object Type: path" "Object Id: -MEOLHicoaU09bHA-Vq5" "Old _path: " "New _path: \"[[\"M\",0,0],[\"L\",700,700]]\"" "Event Name: change:path" "Object Type: path" "Object Id: -MEOLHicoaU09bHA-Vq5" "Old _path: " "New _path: \"[[\"M\",0,0],[\"L\",700,700]]\""
1597100653
The Aaron
Roll20 Production Team
API Scripter
I observed this behavior as well. It doesn't really harm anything since you can't change the path property (and thus can't get in an infinite update cycle). Dragging default tokens into the map has a similar pattern of add,change,change,...  it will sometimes have 2–3 change events on add.  sendChat() from the api also triggers chat events. 
True! Holding alt when dragging prevents those additional events, but at least those events are triggered after "add:graphic". Getting these things nailed down to a consistent behavior sure would be nice! Just another event I'll have to explicitly ignore (although I think one might create some false negatives in my system). Thanks again The Aaron!
1597109802
The Aaron
Roll20 Production Team
API Scripter
I'll have to experiment with the alt drag. Probably still gets a change for token defaults if you've set any.   Btw, for events, the leading _ is required. It rarely comes up, but there are a few places. 
Yup! I'm actually using the leading underscore in all my system just to be certain. I'll see about token default stuff too.