Deleting Object from within its own Script

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Deleting Object from within its own Script

Post by Gage » Wed Jan 21, 2015 11:56 pm

Hello!

Anyone know a way to do the following?

on HandlerName
delete me
end HandlerName

Usually, I do this:

---------------------------------
In Object

on ObjectHandler
put the long id of me into tObject
send "DeleteObject tObject" to card "My Card" in 20 milliseconds
end ObjectHandler

----------------------------------
On the Card

on DeleteMe pObjectID
delete pObjectID
end DeleteMe

-----------------------------------

... or something close to that. However, in this case, my cards will not have the DeleteMe handler on them, hence wanting to "delete me in 20 milliseconds" from the object's own script.


Thanks!
Phil E.

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Deleting Object from within its own Script

Post by Da_Elf » Thu Jan 22, 2015 12:04 am

i usually do the same and put the deleteme script in the main stack so all cards and objects can access it. mine is setup for deleting single objects as well as sequentially numbered objects

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Deleting Object from within its own Script

Post by Klaus » Thu Jan 22, 2015 12:08 am

Hi Phil,

you can actually do something like this:

Code: Select all

on mouseup
  put the long ID of me int tID
  send "delete tID" to this stack in 20 millisecs
end mouseup
and the stack (the engine!) knows what to do and will do it! :D


Best

Klaus

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Deleting Object from within its own Script

Post by Gage » Thu Jan 22, 2015 1:45 am

Klaus,

That's awesome! I didn't realize it accepted a parameter. That's just what I'm looking for; nice and universal.

Thank you both for your responses!
Phil E.

Post Reply