is there a way to set one variable based on another in a module or function?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

is there a way to set one variable based on another in a module or function?

jdawgaz
I have been trying to figure out a clean way of doing this:

lets say I have 2 variables. The premise is that when one of them is set to true, the other has to be set to false and vice versa.

So functionally:

a = true;
b = false;

is there a function or module that can be written, such that if a is set to true, then b will be set to false? and if a is set to false, b will be set to true?

or do I have to always visually check?


--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Openscad developer

The most exciting phrase to hear in science - the one that heralds new discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: is there a way to set one variable based on another in a module or function?

nophead
b = !a;


On 17 July 2017 at 15:54, Jerry Davis <[hidden email]> wrote:
I have been trying to figure out a clean way of doing this:

lets say I have 2 variables. The premise is that when one of them is set to true, the other has to be set to false and vice versa.

So functionally:

a = true;
b = false;

is there a function or module that can be written, such that if a is set to true, then b will be set to false? and if a is set to false, b will be set to true?

or do I have to always visually check?


--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Openscad developer

The most exciting phrase to hear in science - the one that heralds new discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: is there a way to set one variable based on another in a module or function?

Whosawhatsis
In reply to this post by jdawgaz
b = !a is the simplest solution in this specific case. More generally, you can use the ternary operator to set variables conditionally. For an (overly verbose) example:

b = (a == true) ? false : true;

On July 17, 2017 at 07:55:20, Jerry Davis ([hidden email]) wrote:

I have been trying to figure out a clean way of doing this:

lets say I have 2 variables. The premise is that when one of them is set to true, the other has to be set to false and vice versa.

So functionally:

a = true;
b = false;

is there a function or module that can be written, such that if a is set to true, then b will be set to false? and if a is set to false, b will be set to true?

or do I have to always visually check?


--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Openscad developer

The most exciting phrase to hear in science - the one that heralds new discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Loading...