[OpenSCAD] Question on defining a 'color' variable

Parkinbot rudolf at parkinbot.com
Tue Jan 23 14:56:19 EST 2018


I would use array syntax, like this: 

myvar = 1; 
color_ = ["red", "green", "black"]; 
color(color_[myvar]) cube(); 

or if you want to use a more general conditional scheme, you can use the
conditional operator: 

myvar = 1; 
color_ = myvar==1?"red":myvar==2?"green": "black"; 
color(color_) cube();  

The rule is: There are only constants in OpenSCAD. You can define, but not
alter the value of a constant. 



--
Sent from: http://forum.openscad.org/




More information about the Discuss mailing list