discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Is it feasible/logical to change if/else

M
MichaelAtOz
Thu, Dec 29, 2016 12:02 AM

I had some code with a series of transformations and then a module call.
I wanted to change the module call depending on a boolean.

So I did

translate(...)
rotate(...)
etc(...)
if (boolean_test)
module_call(some_params);
else
module_call(some_others); // or perhaps a different_module_call()

Of course it didn't work. So I used '? :', there would be other ways too.

But then I thought, would that be so bad if it could work that way too?


Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

View this message in context: http://forum.openscad.org/Is-it-feasible-logical-to-change-if-else-tp19803.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I had some code with a series of transformations and then a module call. I wanted to change the module call depending on a boolean. So I did translate(...) rotate(...) etc(...) if (boolean_test) module_call(some_params); else module_call(some_others); // or perhaps a different_module_call() Of course it didn't work. So I used '? :', there would be other ways too. But then I thought, would that be so bad if it could work that way too? ----- Admin - PM me if you need anything, or if I've done something stupid... Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- View this message in context: http://forum.openscad.org/Is-it-feasible-logical-to-change-if-else-tp19803.html Sent from the OpenSCAD mailing list archive at Nabble.com.
TP
Torsten Paul
Thu, Dec 29, 2016 12:22 AM

On 12/29/2016 01:02 AM, MichaelAtOz wrote:

Of course it didn't work.

What's the exact code that did not work? This looks ok
to me:


module test(t, b) {
translate(t)
if (b)
cube(8, center = true);
else
sphere(4);
}

test([-10, 0, 0], false);
test([10, 0, 0], true);


ciao,
Torsten.

On 12/29/2016 01:02 AM, MichaelAtOz wrote: > Of course it didn't work. > What's the exact code that did not work? This looks ok to me: ----------------------------------------- module test(t, b) { translate(t) if (b) cube(8, center = true); else sphere(4); } test([-10, 0, 0], false); test([10, 0, 0], true); ----------------------------------------- ciao, Torsten.
M
MichaelAtOz
Thu, Dec 29, 2016 3:52 AM

Hmmm, my bad.

The lines with the blue circles were added (except with different clipAngles

  • I had to recreate it).

See the error, I wasn't thinking straight, turns out it was missing a
semi-colon....

http://forum.openscad.org/file/n19808/my_bad_if.jpg

I was in a hurry, and just changed to '? :' without proper diagnosis.

Sorry to bother.


Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

View this message in context: http://forum.openscad.org/Is-it-feasible-logical-to-change-if-else-tp19803p19808.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Hmmm, my bad. The lines with the blue circles were added (except with different clipAngles - I had to recreate it). See the error, I wasn't thinking straight, turns out it was missing a semi-colon.... <http://forum.openscad.org/file/n19808/my_bad_if.jpg> I was in a hurry, and just changed to '? :' without proper diagnosis. Sorry to bother. ----- Admin - PM me if you need anything, or if I've done something stupid... Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- View this message in context: http://forum.openscad.org/Is-it-feasible-logical-to-change-if-else-tp19803p19808.html Sent from the OpenSCAD mailing list archive at Nabble.com.