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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10430
Joined: Fri Feb 19, 2010 10:17 am

Referring to self?

Post by richmond62 »

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: 2988
Joined: Sun Sep 23, 2007 4:58 pm

Re: Referring to self?

Post by SparkOut »

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: 10430
Joined: Fri Feb 19, 2010 10:17 am

Re: Referring to self?

Post by richmond62 »

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: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Referring to self?

Post by Klaus »

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: 10430
Joined: Fri Feb 19, 2010 10:17 am

Re: Referring to self?

Post by richmond62 »

Super!

I suppose the SEND IN 1 allows the script to finish.
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Referring to self?

Post by Klaus »

Exactly, that is the trick! :-)
Post Reply