I have a problem with If statement in OpenScad. I have 4 variables
a=20;
b=14;
w=1;
c=16;
I want to check witch number is bigger a
or b
.
And after depending who is smaller to take the value of smaller variable(in our case b < a
) and to make a simple operation with c
variable ( c=b-w
).
I tried like this but it doesn't work.
a=20;
b=14;
w=1;
c=16;
if(a>b)
{
c=b-w;
}
if (a<b)
{
c=a-w;
}
if (a==b)
{
c=a-w;
}
It seems logic, but in openscad as I understood you can't change the value of variable inside a If statement. What trick can I use in order to get my goal. Thank you!
OpenSCAD's variable assignment is different. You can only assign variables inside a bracket. So c = b - w
will only be assigned inside the if bracket. Outside if this bracket it will still be 16. Don't ask me why. You can read more in the Documentation of OpenSCAD.