button to change color error
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
button to change color error
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.
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
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
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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: button to change color error
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.
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
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
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
Hi avengine,
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.
The short name of the card is "card id 1002"
Simon
You have to "pass mouseUp" otherwise the mouseUp message gets trapped in the button.on the button just have on mouseUp
end mouseUp
they are empty inside
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.
That comes when you click on the card and not a button.card id 1002: excution error at line n/a (Bject: unknow color) near "card id 1002"
The short name of the card is "card id 1002"

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: button to change color error
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.
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
Hi avengine,
ouch! Please delete that script immediately!
Here is what happens:
You had the (almost) correct script at the beginning:
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:
Please take alook at these stack., great learning resource to get the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
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
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
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
Re: button to change color error
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.
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.