Switch Block Question

Half LifeHalf Life Posts: 479

I am working on a script and I want to read the  base color of the current material and have that output a result matching the RGBA array. It currently looks like this:

 

var oMat = Scene.getPrimarySelection().getObject().getCurrentShape().getMaterial(0); var oEmissionColor = oMat.getBaseColor();switch(oEmissionColor){case [0,1,0,1]:print("Green")break;case [0.0477758,0,0.21952,1]:print("Purple")break;case [1,1,0,1]:print("Yellow")break;case [1,0,0,1]:print("Red")break;case [1,0.21952,0,1]:print("Orange")break;case [0,0.21952,1,1]:print("Blue")break;default:print("this doesn't work")break;}

 

 Everything seems to be fine but the array matches the case array (I checked via print) and the script does not pick it up. Is it just that cases cannot be arrays?

Post edited by Half Life on

Comments

  • Half LifeHalf Life Posts: 479
    edited May 2020

    For anybody else who comes across this issue here is my solution:

    var oMat = Scene.getPrimarySelection().getObject().getCurrentShape().getMaterial(0); var sEmissionColor = oMat.getBaseColor().toString();print(sEmissionColor)switch(sEmissionColor){case "[0,1,0,1]":print("Green")break;case "[0.0477758,0,0.21952,1]":print("Purple")break;case "[1,1,0,1]":print("Yellow")break;case "[1,0,0,1]":print("Red")break;case "[1,0.21952,0,1]":print("Orange")break;case "[0,0.21952,1,1]":print("Blue")break;default:print("this doesn't work")break;}

     

    Post edited by Half Life on
  • Richard HaseltineRichard Haseltine Posts: 96,849

    Rob does add:

    Do note, however, that DzFloatColor and Color objects do not have a common ancestor, so you cannot simply swap one in for the other (but you can construct a new DzFLoatColor from a Color).

Sign In or Register to comment.