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

Delete object (tokens) programmatically via the API

March 19 (11 years ago)
Aaron G.
KS Backer
Is there any way to delete a token (which was created using the createObj method) using the API? I've gone through the documentation, and I don't see any way to do it. If there is no way, then I hope the developers consider that for their to-do list.
March 19 (11 years ago)
Nope.
March 19 (11 years ago)
Aaron G.
KS Backer
Well, that is disappointing. Do you have any work-arounds to deal with the problem? My fallback position was to simply make them very small and move them to the GM layer. However, that doesn't work either because the system crashes when I try to set properties on tokens created with createObj(). (I reported that behavior as a bug in the Bugs forum because there were several other posts of similar issues.) So now I am out of ideas as to how to "get rid of" these tokens that I'm making. (Rather than clicking and deleting them manually, I mean.)
March 19 (11 years ago)
Lithl
Pro
Sheet Author
API Scripter

Aaron G. said:

So now I am out of ideas as to how to "get rid of" these tokens that I'm making. (Rather than clicking and deleting them manually, I mean.)

Nag Riley? =)

Another option, which may or may not be viable depending on what you're trying to accomplish, would be to pool the tokens. In other words, when you "delete" the token, add the token's id to a pool array (probably stored in the session, so you can still have it in later weeks and months), shrink it, move it to the GM layer, off the map, etc.

When you need to "create" a token, check to see if the pool has any ids first. If it does, pop the id off the array, and use that token for your new object. If it doesn't have anything pooled, then you actually create a new one.

March 25 (11 years ago)
I've been looking at these same two issues. They are quite limitting.

Brian, what do you mean by session? Do you mean localstorage or some other language-based session variable? Or do you mean there is some method of storing data for the game session where we can access it later? I suppose having a GM-only text box that gets parsed would do it... but is there a better way?

Thanks!
March 25 (11 years ago)
Aaron G.
KS Backer
I think Brian was talking about the state variable that's available through the API that is persistent across gaming sessions.
https://wiki.roll20.net/API:Objects#Global_Objects
March 25 (11 years ago)
Ohhh, awesome. I vaguely remember seeing the stuff about "Campaign" but I completely missed the info about "state". That's super helpful.

Thanks, Aaron and Brian!
March 25 (11 years ago)
Lithl
Pro
Sheet Author
API Scripter
Yes, thank you Aaron. It's been a while since I wrote a script using state. =)
We have had the power to create objects for quite some time now... Riley, when will we have the power to delete objects? Is it in the pipeline?

Right now I have developed my API to auto populate the map with the relevant spell template as a token when a player casts a spell. I would love for the token to disappear automatically on a timer...
May 27 (11 years ago)
Casey
Sheet Author
Crikey, yea, is this even on the roadmap?
In lieu of deleting the objects, maybe add a script line to move them all to pos x,y on the map layer for a quick delete at a later time. map layer, select group delete. Not ideal, but much quicker than hunting them all down and will keep the maps from getting too klunky.