Page 1 of 1
button to change color error
Posted: Wed May 07, 2014 12:05 am
by avengine
I am following the tutorial in the link below to create buttons to change the text into different color, but I get error on
on mouseup
local tcolor
## use the target function to check which button was pressed
## the short name of the buttons are red, blue and green
## so we can use that to set the color
put the short name of the target into tcolor
set the textcolor of field "text" to tcolor
end mouseup
when I click apply and run it, I got this error
card id 1002: execution error at line n/a (Object: unknown color) near "card id 1002"
but when I click on the button, the color change is fine.
what might be wrong.
thanks.
Re: button to change color error
Posted: Wed May 07, 2014 12:21 am
by Simon
Hi avengine,
looks like you might not have set the name of your field to "text".
And don't forget that script is in your card script not the button script... in the example there are no scripts in the buttons unless you left them in.
Simon
Re: button to change color error
Posted: Thu May 08, 2014 9:22 pm
by avengine
on the card 1002
I just put
on mouseUp
put the short name of the target into tColor
set the textColor of field "text" to tColor
end mouseUp
if I click apply and run
errors
card id 1002: excution error at line n/a (Bject: unknow color) near "card id 1002"
on the button just have on mouseUp
end mouseUp
they are empty inside
the text field did call it text already.
if I click the stop button on card id 1002 window and just go the card and with the run arrow to click the red, blue or green. the text can change color.
but my question is why the error show up and what might be wrong on this step. is there a finish livecode that i can download to see what is wrong on my part.
I have attach a file call button message test3.livecode
thanks.
Re: button to change color error
Posted: Thu May 08, 2014 9:41 pm
by dunbarx
Hi.
Did you try to set the textColor of the field to the name of the card?
Valid colors are based on a palette resident in the program, like "red" or "cornflowerblue". Or explicitly referenced, as in "255,255,0".
But there is no color "card id 1002". If you change that line to substitute "red", does the problem go away?
Craig Newman
Re: button to change color error
Posted: Fri May 09, 2014 2:31 am
by Simon
Hi avengine,
on the button just have on mouseUp
end mouseUp
they are empty inside
You have to "pass mouseUp" otherwise the mouseUp message gets trapped in the button.
on mouseUp
pass mouseUp
end mouseUp
Or remove the mouseUp from the buttons all together.
I would suggest that you start with a new stack, your code does work.
card id 1002: excution error at line n/a (Bject: unknow color) near "card id 1002"
That comes when you click on the card and not a button.
The short name of the card is "card id 1002"
Simon
Re: button to change color error
Posted: Sat May 10, 2014 1:37 pm
by avengine
I did what you suggest, but i hope i am just missing the way the syntax expected.
can you point me to what should i change on this?
as you know i am learning step by step in here, i really need to go thur this step.
thanks.
Re: button to change color error
Posted: Sat May 10, 2014 4:05 pm
by Klaus
Hi avengine,
ouch! Please delete that script immediately!
Here is what happens:
You had the (almost) correct script at the beginning:
Code: Select all
on mouseup
## use the target function to check which button was pressed
## the short name of the buttons are red, blue and green
## so we can use that to set the color
put the short name of the target into tcolor
set the textcolor of field "text" to tcolor
end mouseup
This works, as long you click on the BUTTONS!
BUT when you click NOT on the buttons but somewhere on the CARD, then this:
## put the short name of the target into tcolor
will put the short name of the card into your variable -> "card id 1002"
And you will agree that this is not a color, right?
OK, what to do?
1. At first, remove all (empty) mouseup scripts from your buttons!
2. You need to also handle the case when a user does NOT click on your button.
You can do so by making sure "the target" is a button by checking "the name of the target".
That will give you
a. the TYPE of control -> button, field, card etc...
b. the NAME (short name) of the control
Examples:
button "Red"
card "card id 1002"
etc...
But we only check the TYPE in your case, which is the first WORD of the name of the target:
Code: Select all
on mouseup
put the name of the target into tTargetName
## We check WORD 1 of this, if it is NOT button then we exit the handler immediately:
if word 1 of tTargetName <> "button" then
exit mouseup
end if
##Now we have made sure that a BUTTON has been clicked and we can carry on without any error!
put the short name of the target into tColor
set the textcolor of field "text" to tColor
end mouseup
Please take alook at these stack., great learning resource to get the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
Re: button to change color error
Posted: Tue May 13, 2014 4:21 am
by avengine
Thanks Klaus
your example work very well, I need to learn your sample in detail.
and I can see that this can be a very powerful program.
thanks again for all the help in this forum.