[OpenSCAD] Question on defining a 'color' variable

Jess Askey jess at askey.org
Tue Jan 23 15:19:15 EST 2018

Thank you Doug and Rudolf... that was exactly what I was missing!

-----Original Message-----
From: Discuss [mailto:discuss-bounces at lists.openscad.org] On Behalf Of Parkinbot
Sent: Tuesday, January 23, 2018 12:56 PM
To: discuss at lists.openscad.org
Subject: Re: [OpenSCAD] Question on defining a 'color' variable

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/

OpenSCAD mailing list
Discuss at lists.openscad.org

More information about the Discuss mailing list