[Closed] Setting wirecolors of the copied objects
Hi,
I’m trying to change wirecolor of my copied objects. This is a piece od code:
_substeps = 25
for i=1 to _substeps do
(
global colorStep = 255/_substeps
colorValue += colorStep
ObjCopy = copy $GS
ObjCopy.wirecolor = [colorValue, colorValue, colorValue]
)
And i get error:
“Unable to convert: [25,25,25] to type: Float”
Which does not make sense since RGB is a vector not a float!
So, does colorValue contain a point3 value? On a side note, why is colorStep a global variable and why do you keep calculating it in each iteration when it doesn’t change? Anyway, changing wirecolor like this works without issues:
try destroyDialog wirecolorFun catch()
rollout wirecolorFun "Wirecolor Fun"
(
colorPicker cpSource color:yellow across:2
spinner spnSteps "Steps: " type:#integer range:[0,256,10]
colorPicker cpTarget color:red across:2
button btnMakeTheHue "Make the Hue"
on btnMakeTheHue pressed do
(
local obj = selection[1]
local clrStep = (cpTarget.color - cpSource.color)/spnSteps.value
local clr = cpSource.color
local posStep = [(obj.max - obj.min).x, 0, 0]
local pos = obj.pos
for s = 1 to spnSteps.value do
copy obj wirecolor:(clr += clrStep) pos:(pos += posStep)
)
)
createDialog wirecolorFun
I can’t reproduce your error. Added some lines for testing pourposes and it works.
(
b = box()
b.name = "GS"
_substeps = 25
colorValue = 0
for i=1 to _substeps do
(
colorStep = 255/_substeps
colorValue += colorStep
ObjCopy = copy $GS
ObjCopy.pos.x += i*26
ObjCopy.wirecolor = [colorValue, colorValue, colorValue]
)
)
Hi,
I’ve found that somewhere in the beggining I had already declared a colorValue as a float. This part got me confused because listener errored on that part (this part of code).
As for keeping a variable global. I’m just a begginer in coding and I found that if I make a variable global it somehow prevent from errors when I want to use the same variable in another “button”
Having declared the variable “colorValue” as float should not produce any error. However if you have declared it as point3, then it will error out.
This will produce the same error as you have, because it is trying to put a point3 value inside each of the components of another point3 value:
(
b = box()
b.name = "GS"
_substeps = 25
colorValue = [15,15,15]
--colorValue = 0.0 -- This won't produce any error
for i=1 to _substeps do
(
colorStep = 255/_substeps
colorValue += colorStep
ObjCopy = copy $GS
ObjCopy.pos.x += i*26
ObjCopy.wirecolor = [colorValue, colorValue, colorValue]
)
)
-- Unable to convert: [25,25,25] to type: Float