Referring to self?

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
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Referring to self?

Post by richmond62 » Wed Jul 03, 2024 1:47 pm

Imagine a button called "B1" containing the script:

Code: Select all

on mouseUp
delete me
end mouseUp
This will NOT work, and generate the following error message:

Code: Select all

object's script is executing
This IS problematic as I wish to delete an object from inwith its own code if certain conditions are satisfied . . .

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Re: Referring to self?

Post by SparkOut » Wed Jul 03, 2024 2:36 pm

I'm pretty sure you can't. Why would you need to?

You could send the long name of me from the control's script to a handler in the stack script or library that takes the parameter and does a bit of error trapping, then deletes the object named in that parameter if error trapping says so.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Re: Referring to self?

Post by richmond62 » Wed Jul 03, 2024 2:54 pm

Why would you need to?
Let's suppose you have a stack with a template image of, say, a fish.

Each time you click on the template fish it clones, and renames the clone.

Now our end-user has to drag the cloned image to a fishpond image: each time s/he manages s/he gets a point.

Each time s/he doesn't manage to drag "fisho" to the pond, the fish vanishes (i.e. deletes).

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

Re: Referring to self?

Post by Klaus » Wed Jul 03, 2024 4:42 pm

This works with my example button:

Code: Select all

on mouseup
   put the long ID of me into tID
   send "delete tID" to this cd in 1
end mouseup

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10098
Joined: Fri Feb 19, 2010 10:17 am

Re: Referring to self?

Post by richmond62 » Wed Jul 03, 2024 5:08 pm

Super!

I suppose the SEND IN 1 allows the script to finish.

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

Re: Referring to self?

Post by Klaus » Wed Jul 03, 2024 5:14 pm

Exactly, that is the trick! :-)

Post Reply