Beginner Confuse

classic Classic list List threaded Threaded
6 messages Options
SNT
Reply | Threaded
Open this post in threaded view
|

Beginner Confuse

SNT
Hello together,

I'm a beginner in OpenSad and I'm really confused about the result of this
simple example:

Code:
Size=3;
if (5>2) {Size=6; echo("Size=",Size);}
echo("Size=",Size);

Result:
ECHO: "Size=", 6
ECHO: "Size=", 3

Why is the latest echo 3 and not 6? It seems to me that in 'if' condition
variables cannot be set.

Best regards and thank you in advane for your help!

Sven





-----
I'm using OpenScad Version 2019.05
--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
I'm using OpenScad Version 2019.05
Reply | Threaded
Open this post in threaded view
|

Re: Beginner Confuse

Ronaldo
I suggest that you read https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/General#Scope_of_variables and after that bring your doubts here. I will be glad to answer them.

Em seg., 25 de mai. de 2020 às 16:22, SNT <[hidden email]> escreveu:
Hello together,

I'm a beginner in OpenSad and I'm really confused about the result of this
simple example:

Code:
Size=3;
if (5>2) {Size=6; echo("Size=",Size);}
echo("Size=",Size);

Result:
ECHO: "Size=", 6
ECHO: "Size=", 3

Why is the latest echo 3 and not 6? It seems to me that in 'if' condition
variables cannot be set.

Best regards and thank you in advane for your help!

Sven





-----
I'm using OpenScad Version 2019.05
--
Sent from: http://forum.openscad.org/

_______________________________________________
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
|

Re: Beginner Confuse

nophead
In reply to this post by SNT
No the Size you define inside braces is a different version and does not last outside the braces.

Use something like this.

Size = 5 > 2 ? 6 : 3;

echo(Size);


On Mon, 25 May 2020 at 16:22, SNT <[hidden email]> wrote:
Hello together,

I'm a beginner in OpenSad and I'm really confused about the result of this
simple example:

Code:
Size=3;
if (5>2) {Size=6; echo("Size=",Size);}
echo("Size=",Size);

Result:
ECHO: "Size=", 6
ECHO: "Size=", 3

Why is the latest echo 3 and not 6? It seems to me that in 'if' condition
variables cannot be set.

Best regards and thank you in advane for your help!

Sven





-----
I'm using OpenScad Version 2019.05
--
Sent from: http://forum.openscad.org/

_______________________________________________
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
SNT
Reply | Threaded
Open this post in threaded view
|

Re: Beginner Confuse

SNT
In reply to this post by Ronaldo

Thank you pretty much Ronaldo!

 

I didn’t read this topic so far. Now It‘s clear to me and I can proceed!

 

Best regards Sve (SNT)

 

 

 

Von: Discuss <[hidden email]> Im Auftrag von Ronaldo Persiano
Gesendet: Montag, 25. Mai 2020 18:13
An: OpenSCAD general discussion <[hidden email]>
Betreff: Re: [OpenSCAD] Beginner Confuse

 

I suggest that you read https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/General#Scope_of_variables and after that bring your doubts here. I will be glad to answer them.

 

Em seg., 25 de mai. de 2020 às 16:22, SNT <[hidden email]> escreveu:

Hello together,

I'm a beginner in OpenSad and I'm really confused about the result of this
simple example:

Code:
Size=3;
if (5>2) {Size=6; echo("Size=",Size);}
echo("Size=",Size);

Result:
ECHO: "Size=", 6
ECHO: "Size=", 3

Why is the latest echo 3 and not 6? It seems to me that in 'if' condition
variables cannot be set.

Best regards and thank you in advane for your help!

Sven





-----
I'm using OpenScad Version 2019.05
--
Sent from: http://forum.openscad.org/

_______________________________________________
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
I'm using OpenScad Version 2019.05
Reply | Threaded
Open this post in threaded view
|

Re: Beginner Confuse

MostlyHarmless
In reply to this post by nophead
This is a behavior that seems to surprise a lot of people new to OpenSCAD. The language looks like a procedural language (something like C or Java), but it isn't. Once you realize that these aren't statements, that are executed one after another, the issue makes more sense.

The best explanation I have found is the one from kevfquinn in this thread: https://www.thingiverse.com/groups/openscad/forums/general/topic:31166


Regards, Jan



On Mon, May 25, 2020 at 12:30 PM nop head <[hidden email]> wrote:
No the Size you define inside braces is a different version and does not last outside the braces.

Use something like this.

Size = 5 > 2 ? 6 : 3;

echo(Size);


On Mon, 25 May 2020 at 16:22, SNT <[hidden email]> wrote:
Hello together,

I'm a beginner in OpenSad and I'm really confused about the result of this
simple example:

Code:
Size=3;
if (5>2) {Size=6; echo("Size=",Size);}
echo("Size=",Size);

Result:
ECHO: "Size=", 6
ECHO: "Size=", 3

Why is the latest echo 3 and not 6? It seems to me that in 'if' condition
variables cannot be set.

Best regards and thank you in advane for your help!

Sven





-----
I'm using OpenScad Version 2019.05
--
Sent from: http://forum.openscad.org/

_______________________________________________
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


--
Jan Wieck
Principal Database Engineer

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

Re: Beginner Confuse

SNT
Hello together,

Actually I use the ? symbol from 'nop head's suggestion  and i'm feeling pretty much comfortable to this very short code implemenation. I have been working since last year on OpenScad and for my application its the very best tool for my 3D objects.
After some challenges with 'too long rendering time' ( obviously a typical beginner argument), mainly based on lots of extrude of dxf file commands, I easily fixed the time problem by closing the lines in the dxf file and the use of $fa instead of $fn. In the meanwhile I feel pretty much fine and for me its not a problem to wait one or two hours on the rendering. Thank you very  much again for the support I got in this forum!

Greetings from Sven (SNT) 

Am 25.05.2020 um 21:56 schrieb Jan Wieck <[hidden email]>:

This is a behavior that seems to surprise a lot of people new to OpenSCAD. The language looks like a procedural language (something like C or Java), but it isn't. Once you realize that these aren't statements, that are executed one after another, the issue makes more sense.

The best explanation I have found is the one from kevfquinn in this thread: https://www.thingiverse.com/groups/openscad/forums/general/topic:31166


Regards, Jan



On Mon, May 25, 2020 at 12:30 PM nop head <[hidden email]> wrote:
No the Size you define inside braces is a different version and does not last outside the braces.

Use something like this.

Size = 5 > 2 ? 6 : 3;

echo(Size);


On Mon, 25 May 2020 at 16:22, SNT <[hidden email]> wrote:
Hello together,

I'm a beginner in OpenSad and I'm really confused about the result of this
simple example:

Code:
Size=3;
if (5>2) {Size=6; echo("Size=",Size);}
echo("Size=",Size);

Result:
ECHO: "Size=", 6
ECHO: "Size=", 3

Why is the latest echo 3 and not 6? It seems to me that in 'if' condition
variables cannot be set.

Best regards and thank you in advane for your help!

Sven





-----
I'm using OpenScad Version 2019.05
--
Sent from: http://forum.openscad.org/

_______________________________________________
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


--
Jan Wieck
Principal Database Engineer
_______________________________________________
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
I'm using OpenScad Version 2019.05