Page 1 of 1

"me" syntax question

Posted: Wed Jul 16, 2008 10:06 am
by ac11ca
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]

Posted: Wed Jul 16, 2008 10:35 am
by gyroscope
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

Posted: Wed Jul 16, 2008 10:39 am
by Mark
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

Posted: Wed Jul 16, 2008 1:37 pm
by ac11ca
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