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

Question about remove() function

Hi! So, I'm having trouble removing a couple graphic objects.  I've never had this problem before... I swear.  Seriously though, I know they are graphic objects cause I log object.get("_type") as graphic.  If I use object.remove(), then call that object, should it return "undefined"? Right now it's logging  [object][object] even after I remove it. obj1.obj.remove(); log("obj1.obj type="+ String(obj1.obj.get("_type"))) log("obj1.obj after removal:"+obj1.obj) logs as: "obj1.obj type=graphic" "obj1.obj after removal:[object Object]" I'm sure it's something obvious or silly, I just can't see it!  Anyway, I've managed a work around for now, so this is more just to satisfy my curiosity.  Thanks.
1495417412

Edited 1495417486
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The [object Object] is because it's an object being logged in a string format. I'd guess that it becomes null (which is still an object in javascript). The real question is, "is it removing it from the VTT?" though.
1495420782

Edited 1495421242
The Aaron
Pro
API Scripter
Yes, it should be removed from the VTT.  The .remove() function likely sends a remove message up to the Firebase where the object gets synchronized out to the various VTT clients and the API.  As such, it's an asynchronous operation so the object will still technically exist until the operation completes at some later point.  Even when it has finished, references to the object that persist will likely still point to a valid Javascript object, though it won't be backed by the Firebase anymore.  Best practice would be once you've called .remove(), treat it as if the object doesn't exist anymore, and get rid of any references you have to it (particularly if you're storing any sort of cache of the object).
1495422311
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The Aaron said: Yes, it should be removed from the VTT.  The .remove() function likely sends a remove message up to the Firebase where the object gets synchronized out to the various VTT clients and the API.  As such, it's an asynchronous operation so the object will still technically exist until the operation completes at some later point.  Even when it has finished, references to the object that persist will likely still point to a valid Javascript object, though it won't be backed by the Firebase anymore.  Best practice would be once you've called .remove(), treat it as if the object doesn't exist anymore, and get rid of any references you have to it (particularly if you're storing any sort of cache of the object). Yep, I was just trying to make sure that they weren't also having a problem with the actual removal on the VTT.
Thank you.  I think I need to read up how exactly an asynchronous operation works.  I appreciate the responses.
1495463354
The Aaron
Pro
API Scripter
Here's a very small bit about it on the wiki:&nbsp; <a href="https://wiki.roll20.net/API:Use_Guide#A_Treatise_o" rel="nofollow">https://wiki.roll20.net/API:Use_Guide#A_Treatise_o</a>...