Hi,
I want to deside what to show/render and I used a string variable to have
clear description. And I have "both" as part of the variant what should
something more. So every object should be visible with its own name and
"both". I decided to use logical OR. But the comparison makes an error I
don't know yet.
Let me give you this example. I use only view="body" and true/false tool to
show the logic.
// scad
view = "body";
echo(view_check = view);
view_check1 = (view == "bla" || "both") ? true : false ;
echo (view_check1 = view_check1);
// this echo should say false because both strings are wrong
view_check2 = (view == ("body" || "both")) ? true : false ;
echo (view_check2 = view_check2);
// this echo should be true because view = "body" is true
// end of scad
The result of echos is confusing:
ECHO: view_check = "body"
ECHO: view_check1 = true
ECHO: view_check2 = false
The first echo is just to see the correct input.
The second one should be false because no "bla" and no "both" is there, but
it is true ?
The third echo should be true because "body" is one true option, but it
is false ?
The difference between view_check1 and 2 is, that I added a bracket in
order to get rid of the error but it made the confusion worse..
Can you explain me what I'm doing wrong and how to do the comparison
correctly?
Try view_check1 = view == "bla" || view == "both";
P.S. "? true : false" is really bad style.
On 6/4/2020 7:12 PM, dpa wrote:
Hi,
I want to deside what to show/render and I used a string variable to
have clear description. And I have "both" as part of the variant
what should something more. So every object should be visible with its
own name and "both". I decided to use logical OR. But the comparison
makes an error I don't know yet.
Let me give you this example. I use only view="body" and true/false tool
to show the logic.
// scad
view = "body";
echo(view_check = view);
view_check1 = (view == "bla" || "both") ? true : false ;
echo (view_check1 = view_check1);
// this echo should say false because both strings are wrong
view_check2 = (view == ("body" || "both")) ? true : false ;
echo (view_check2 = view_check2);
// this echo should be true because view = "body" is true
// end of scad
The result of echos is confusing:
ECHO: view_check = "body"
ECHO: view_check1 = true
ECHO: view_check2 = false
The first echo is just to see the correct input.
The second one should be false because no "bla" and no "both" is
there, but it is true ?
The third echo should be true because "body" is one true option, but
it is false ?
The difference between view_check1 and 2 is, that I added a bracket in
order to get rid of the error but it made the confusion worse..
Can you explain me what I'm doing wrong and how to do the comparison
correctly?
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
You just need
view_check1 = view == "bla" || view =="both";
No need to test to make true and false because == returns true or false and
you must compare view twice.
On Thu, 4 Jun 2020 at 17:12, dpa sc@pankd.de wrote:
Hi,
I want to deside what to show/render and I used a string variable to have
clear description. And I have "both" as part of the variant what should
something more. So every object should be visible with its own name and
"both". I decided to use logical OR. But the comparison makes an error I
don't know yet.
Let me give you this example. I use only view="body" and true/false tool
to show the logic.
// scad
view = "body";
echo(view_check = view);
view_check1 = (view == "bla" || "both") ? true : false ;
echo (view_check1 = view_check1);
// this echo should say false because both strings are wrong
view_check2 = (view == ("body" || "both")) ? true : false ;
echo (view_check2 = view_check2);
// this echo should be true because view = "body" is true
// end of scad
The result of echos is confusing:
ECHO: view_check = "body"
ECHO: view_check1 = true
ECHO: view_check2 = false
The first echo is just to see the correct input.
The second one should be false because no "bla" and no "both" is there, but
it is true ?
The third echo should be true because "body" is one true option, but
it is false ?
The difference between view_check1 and 2 is, that I added a bracket in
order to get rid of the error but it made the confusion worse..
Can you explain me what I'm doing wrong and how to do the comparison
correctly?
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Try
view_check2 = view == "body" || view == "both";
Regards, Jan
On Thu, Jun 4, 2020 at 12:13 PM dpa sc@pankd.de wrote:
Hi,
I want to deside what to show/render and I used a string variable to have
clear description. And I have "both" as part of the variant what should
something more. So every object should be visible with its own name and
"both". I decided to use logical OR. But the comparison makes an error I
don't know yet.
Let me give you this example. I use only view="body" and true/false tool
to show the logic.
// scad
view = "body";
echo(view_check = view);
view_check1 = (view == "bla" || "both") ? true : false ;
echo (view_check1 = view_check1);
// this echo should say false because both strings are wrong
view_check2 = (view == ("body" || "both")) ? true : false ;
echo (view_check2 = view_check2);
// this echo should be true because view = "body" is true
// end of scad
The result of echos is confusing:
ECHO: view_check = "body"
ECHO: view_check1 = true
ECHO: view_check2 = false
The first echo is just to see the correct input.
The second one should be false because no "bla" and no "both" is there, but
it is true ?
The third echo should be true because "body" is one true option, but
it is false ?
The difference between view_check1 and 2 is, that I added a bracket in
order to get rid of the error but it made the confusion worse..
Can you explain me what I'm doing wrong and how to do the comparison
correctly?
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
--
Jan Wieck
Principal Database Engineer
thank you!
Am Do., 4. Juni 2020 um 18:31 Uhr schrieb Jan Wieck jan@wi3ck.info:
Try
view_check2 = view == "body" || view == "both";
Regards, Jan
On Thu, Jun 4, 2020 at 12:13 PM dpa sc@pankd.de wrote:
Hi,
I want to deside what to show/render and I used a string variable to have
clear description. And I have "both" as part of the variant what should
something more. So every object should be visible with its own name and
"both". I decided to use logical OR. But the comparison makes an error I
don't know yet.
Let me give you this example. I use only view="body" and true/false tool
to show the logic.
// scad
view = "body";
echo(view_check = view);
view_check1 = (view == "bla" || "both") ? true : false ;
echo (view_check1 = view_check1);
// this echo should say false because both strings are wrong
view_check2 = (view == ("body" || "both")) ? true : false ;
echo (view_check2 = view_check2);
// this echo should be true because view = "body" is true
// end of scad
The result of echos is confusing:
ECHO: view_check = "body"
ECHO: view_check1 = true
ECHO: view_check2 = false
The first echo is just to see the correct input.
The second one should be false because no "bla" and no "both" is
there, but it is true ?
The third echo should be true because "body" is one true option, but
it is false ?
The difference between view_check1 and 2 is, that I added a bracket in
order to get rid of the error but it made the confusion worse..
Can you explain me what I'm doing wrong and how to do the comparison
correctly?
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
--
Jan Wieck
Principal Database Engineer
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org