Notifications
Clear all

[Closed] color access mistake

hello, can someone explain why do i get – undefined – in the listener when i run the following script ? i guess its something with the color access, but i dont know why as its the first time im writing a code that involves color values.

thanks.

(
  b = box()
  color1 = (color 200 10 10)

  b.material = standard diffuse: color1

  NcolorState = b.material.diffuse
  if NcolorState == color1 do cylinder()
)
5 Replies

You will have same problem with any value (point2, point3, matrix, color, array etc).
If you want to compare something then just convert value to string

(
    b = box()
    color1 = (color 200 10 10)
  
    b.material = standard diffuse: color1
  
    NcolorState = b.material.diffuse
    if NcolorState as string == color1 as string do cylinder()
  )

thank you very much !
should i do that like every time ?
because when i have point3 values i believe it does work to directly compare them.

No is not. Try to replace “as string” with “as [color=Plum]point3[/color]” and you’ll see. Same problem

This is a text from maxscript help
“A simpler alternative is to compare the two arrays by turning them into strings.
But you can compare color value like this

if NcolorState.r == color1.r and NcolorState.g == color1.g and \
 NcolorState.b == color1.b do cylinder()

will know that from now on…
thanks a lot !