Page 1 of 1

Setting color from it

Posted: Fri Apr 25, 2014 10:07 pm
by michel_bujardet
I am trying to use the result of the color selector with

Code: Select all

   answer color with "blue"
   answer it
   set the textcolor of field "text" to it
I get an error :(

After answer color, the value of it is for instance 255,169,183.

When used as litteral the color is applied.

Code: Select all

set the textcolor of field "text" to 255,169,183
works fine.

But

Code: Select all

set the textcolor of field "text" to it
generates the error : execution error at line n/a (Object: unknown color) near "OK".

Thank you for your help.

Re: Setting color from it

Posted: Fri Apr 25, 2014 10:43 pm
by dunbarx
Hi.

Welcome to learning how Livecode works. This is going to be great.

Do you know how to debug a script? If so, put a breakpoint at the first line. When you get to the line that sets the textcolor, what is in the variable "it"? How did it get there?

If you get the answers to these questions, please write back. If you do not, please write back. A hint: the local variable "it" is often populated by common native processes. You need to watch these carefully, usually wanting to offload the results of, say, "answer" commands to another variable immediately.

Waiting to hear...

Craig Newman

Re: Setting color from it

Posted: Sat Apr 26, 2014 4:20 am
by srbarlow3

Code: Select all

   answer color with "blue"
   answer it
   set the textcolor of field "text" to it
Here's what's happening.

the first line opens the color dialog with blue selected as default
(blue just happens to be 0,0,255 in RGB values)
When you click "OK" it assigned the blue value (assuming you didn't select another color while the dialogs open) to it

the second line opens a dialog wit it as the dialog test...the color values. When you click "ok" ( default dialog button) to close the "answer" dialog it assigns "OK" (the value clicked) to it

the third line tries to set the textColor to "OK" ...obviously not a color value that is recognized like 0,0255 or "blue"

Just remove the middle "answer it" and "it" from line one is not replaced with "OK" and it works fine

hope this is clear

Russ

Re: Setting color from it

Posted: Sat Apr 26, 2014 7:00 am
by michel_bujardet
srbarlow3 wrote:the second line opens a dialog wit it as the dialog test...the color values. When you click "ok" ( default dialog button) to close the "answer" dialog it assigns "OK" (the value clicked) to it

Russ
I did not realize answer was modifying the content of it ! I should have used another variable for the display. I will remember that.

Thank you for your explanation, Russ.

Just before I read this post, I was using split to separate each color and present them with comas. It worked, but I could have done without ;)

Re: Setting color from it

Posted: Sat Apr 26, 2014 4:41 pm
by dunbarx
Hmmm. Russ is spot on. Remember what I posted. There are several instances of just what tripped you up. These all need to be learned...
. A hint: the local variable "it" is often populated by common native processes. You need to watch these carefully, usually wanting to offload the results of, say, "answer" commands to another variable immediately.
Craig

Re: Setting color from it

Posted: Sat Apr 26, 2014 5:51 pm
by srbarlow3
As dunbarx said, it is a good idea to store the returned "it" in another container(variable) right after it's returned to remove any doubt

Good Luck

Russ