[Closed] Urgent – Convert string to color?
I’m trying to convert a string to a color and I can’t seem to get it working.
data = “color 0 0 0”
$.material.diffuse = data as color
This doesn’t work…
I can also get the data as
Data = “[0,0,0]”
Tried $.material.diffuse = color data
Can’t figure out how to convert the data, do I need to use Execute or something?
If you don’t care about speed
data = "color 0 0 0"
j = execute data
$.material.diffuse = j
That works, though i’m sure there is another way to do it
data = color 0 255 0
$teapot01.mat.diffuse = data
Remove the “” from the data code line as it is a color value and NOT a string value!
Mike
He knows, that but he needs to convert it from a string into a color value, probably because he is reading the data from a txt file or xml or something like that.
I’ve run into this issue myself before and so far using execute has been the only solution. I’d love to see see a better one however.
how about this?
data = "color 0 0 0"
dA = filterstring data " "
$.material.diffuse = [dA[2]as float,dA[3]as float,dA[4]as float]
Realised as I wrote it that it was Execute that I needed…
Any of the following work…
val = "[255,255,255]"
col = (execute val) as color
val = "color 255 255 255"
col = execute val
val = "(color 255 255 255)"
col = execute val
val = "point3 255 255 255"
col = (execute val) as color