"me" syntax question

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ac11ca
Posts: 41
Joined: Sun Mar 16, 2008 2:22 am

"me" syntax question

Post by ac11ca » Wed Jul 16, 2008 10:06 am

I have the following handler in the card script:

Code: Select all

on Playing
set the backgroundcolor of me to "250,100,100"
end Playing
I then have TWO different buttons with the following script:

Code: Select all

on mouseDown
Playing
end mouseDown
When I click the either of the buttons, the card changes colour rather than the clicked button. I only want the clicked button to change color and am trying to avoid putting code into the buttons....Any ideas?

Thanks,
Adrian[/code]

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Wed Jul 16, 2008 10:35 am

Hi ac11ca

You've put

Code: Select all

set the backgroundcolor of me to "250,100,100"
in your card script so "me" refers to the card, not the button.

If you change the script in the card to:

Code: Select all

 on Playing 
if the mouseDown of button"X" is true then
set the backgroundcolor of button "X" to "250,100,100"
end if
if the mouseDown of button"Y" is true then
set the backgroundcolor of button "Y" to "250,100,100"  
end if
end Playing 
that'll work as you want. (I'm sure there's another more straightforward way as well)

If there's just this small bit of code for the Playing handler, and not too many buttons, I'd personally forget calling up the Player handler from the card and put:

Code: Select all

on mouseDown
set the backgroundcolor of me to "250,100,100"
end mouseDown 
in each button script...but as you wrote:
...trying to avoid putting code into the buttons
you don't want to do this...

For curiosity's sake, may I ask why please?

Anyway, hope that helps...

:)

PS Another way to change the background colour of the button would be to make an icon graphic with your colour change and refer to it in the Inspector > Icons and Border
Last edited by gyroscope on Wed Jul 16, 2008 11:27 am, edited 3 times in total.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Jul 16, 2008 10:39 am

Dear Adrian,

"Me" always refers to the object containing the script. If you want to refer to the object clicked on by the user, use "the target":

Code: Select all

 	on Playing
  set the backgroundcolor of the target to "250,100,100"
end Playing 
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

ac11ca
Posts: 41
Joined: Sun Mar 16, 2008 2:22 am

Post by ac11ca » Wed Jul 16, 2008 1:37 pm

Thanks gyroscope, I was trying to do something similar but I knew there was a simpler way (as pointed out by Mark - thanks!).

I was trying to keep coding out of the button simply because I have coding everywhere and am trying to keep the coding for the one operation in the one place (in this case, in the card script).

Cheers,
Adrian

Post Reply