A group that can delete itself

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

A group that can delete itself

Post by kaveh1000 » Tue Feb 19, 2019 10:13 am

I have a number of groups on a card. I want a button on each group that deletes the entire group (including itself) when clicked.

I attach my minimal example and can't find a way to do this. I am sure obvious for the gods on this forum! Any ideas pls?
Attachments
delete me.zip
(1.03 KiB) Downloaded 170 times
Kaveh

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: A group that can delete itself

Post by bogs » Tue Feb 19, 2019 11:18 am

kaveh1000 wrote:
Tue Feb 19, 2019 10:13 am
I am sure (it is?) obvious for the gods on this forum! Any ideas pls?
Sure, we've got lots of ideas, come back on the 8th day, we're a little busy right now.
signed : local wood sprite :P
(Just kidding :wink: )

First, let me ask if you already saw 'deleteGroup' in the dictionary. If not, it has an example attached to it-

Code: Select all

on deleteGroup -- remove the group being deleted from a list
  get lineOffset(the short name of the target,field "Groups List")
  delete line it of field "Groups List"
  pass deleteGroup
end deleteGroup
If your asking something else or something more specific, feel free to elaborate.
Image

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: A group that can delete itself

Post by Klaus » Tue Feb 19, 2019 11:32 am

Hi Kaveh,

as an admin I can assure there are only humans here in this forum! 8)

Problem:
You cannot delete an object whose script is currently being executed, so the trick is to "outsource" the actual "delete" command!

Do like this:
Button script

Code: Select all

on mouseup
   put the long ID of the owner of me into yowsayowsayowsa
   send "delete_it yowsayowsayowsa" to this cd in 1
end mouseup
When using THE LONG ID we do not need to specify the type of object (button, field, group, whatever).

Card script

Code: Select all

command delete_it tObject
   delete tObject
end delete_it
Tested and works!


Best

Klaus

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: A group that can delete itself

Post by bogs » Tue Feb 19, 2019 11:47 am

Klaus wrote:
Tue Feb 19, 2019 11:32 am
as an admin I can assure there are only humans here in this forum! 8)
I don't remember seeing the checkbox for sprites when I signed up :twisted:
Image

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: A group that can delete itself

Post by Klaus » Tue Feb 19, 2019 11:49 am

I KNEW you are a fairy queen! 8)

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: A group that can delete itself

Post by bogs » Tue Feb 19, 2019 11:54 am

Selection_004.png
We ain't all pixies :P
Selection_004.png (8.1 KiB) Viewed 4903 times
Never saw the movie "Tooth Fairy" eh? :twisted:
Image
This is a poster for the film Tooth Fairy. The poster art copyright is believed to belong to the distributor of the film, 20th Century Fox, the publisher of the film or the graphic artist.
Image

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: A group that can delete itself

Post by Klaus » Tue Feb 19, 2019 12:03 pm

bogs wrote:
Tue Feb 19, 2019 11:54 am
Never saw the movie "Tooth Fairy" eh? :twisted:
Sure I did, with my friend Dwayne and the lovely Julie Andrews! :D

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: A group that can delete itself

Post by kaveh1000 » Tue Feb 19, 2019 12:42 pm

Thank you Klaus. You are still a god when viewed from down here. ;-)

Works nicely. My error was putting the delete handler in the group.
Kaveh

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: A group that can delete itself

Post by Klaus » Tue Feb 19, 2019 1:54 pm

Hi Kaveh,

this is just 20 years of experience in working with Livecode and its ancestors (MetaCard, Revolution). And the first three years without internet access (yes, those were the days), so just try & error, hard but highly effective! :D

Best

Klaus

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: A group that can delete itself

Post by kaveh1000 » Tue Feb 19, 2019 2:10 pm

:-) I started with Hypercard beta, before Apple had a manual. Been dabbling ever since. The love never goes away... :-)
Kaveh

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: A group that can delete itself

Post by bogs » Tue Feb 19, 2019 2:52 pm

Meh, you spoiled brats! InterWebz, PSHAW :P Manuals... we used hieroglyphs!!

When I started, all we had was an Antikythera device, a chisel, and an Abacus, and we LIKED it that way :P

I can tell you many was the time we had to walk to the temple in 25 cubits of snow, UPHILL both ways, just to attend the ritual sacrifices... :twisted:
Image

Post Reply

Return to “Talking LiveCode”