Module Variables

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

Module Variables

Jeshua Lacock

Greetings,

I am trying to set a local variable in a module, but I either get a syntax error or if I use "assign" it seems to have no effect.

This is what I have tried:

module bearingStand(isShort) {

        sideCenter = 100.0;

        if (isShort == true) {
                assign(sideCenter = 115);
        }
        else {
                assign(sideCenter = 110);
        }
}

And:

module bearingStand(isShort) {

        sideCenter = 100.0;

        if (isShort == true) {
                sideCenter = 115;
        }
        else {
                sideCenter = 110;
        }
}

Any suggestions would be greatly appreciated!


Thanks,

Jeshua Lacock
Founder/Engineer
3DTOPO Incorporated
<http://3DTOPO.com>
Phone: 208.462.4171


Reply | Threaded
Open this post in threaded view
|

Re: Module Variables

Miro Hrončok
This works for me.


module bearingStand(isShort) {

        if (isShort == true) {
                assign(sideCenter=115);
        }
        else {
                assign(sideCenter=110);
        }
}

(no sideCenter = 100.0)

Miro Hrončok

Jabber: [hidden email]
Telefon: +420777974800


2013/2/27 Jeshua Lacock <[hidden email]>:

>
> Greetings,
>
> I am trying to set a local variable in a module, but I either get a syntax error or if I use "assign" it seems to have no effect.
>
> This is what I have tried:
>
> module bearingStand(isShort) {
>
>         sideCenter = 100.0;
>
>         if (isShort == true) {
>                 assign(sideCenter = 115);
>         }
>         else {
>                 assign(sideCenter = 110);
>         }
> }
>
> And:
>
> module bearingStand(isShort) {
>
>         sideCenter = 100.0;
>
>         if (isShort == true) {
>                 sideCenter = 115;
>         }
>         else {
>                 sideCenter = 110;
>         }
> }
>
> Any suggestions would be greatly appreciated!
>
>
> Thanks,
>
> Jeshua Lacock
> Founder/Engineer
> 3DTOPO Incorporated
> <http://3DTOPO.com>
> Phone: 208.462.4171
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
> http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

Re: Module Variables

Joel Bodenmann
I can confirm that this doesn't work on my OpenSCAD version 2013.02.11.


Kind regards,

~ Joel Bodenmann


On 02/27/2013 11:23 AM, Miro Hrončok wrote:
This works for me.


module bearingStand(isShort) {

        if (isShort == true) {
                assign(sideCenter=115);
        }
        else {
                assign(sideCenter=110);
        }
}

(no sideCenter = 100.0)

Miro Hrončok

Jabber: [hidden email]
Telefon: +420777974800


2013/2/27 Jeshua Lacock [hidden email]:
Greetings,

I am trying to set a local variable in a module, but I either get a syntax error or if I use "assign" it seems to have no effect.

This is what I have tried:

module bearingStand(isShort) {

        sideCenter = 100.0;

        if (isShort == true) {
                assign(sideCenter = 115);
        }
        else {
                assign(sideCenter = 110);
        }
}

And:

module bearingStand(isShort) {

        sideCenter = 100.0;

        if (isShort == true) {
                sideCenter = 115;
        }
        else {
                sideCenter = 110;
        }
}

Any suggestions would be greatly appreciated!


Thanks,

Jeshua Lacock
Founder/Engineer
3DTOPO Incorporated
<http://3DTOPO.com>
Phone: 208.462.4171

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

Re: Module Variables

nophead
assign only applies to the tree beneath it e.g.

assign(a = 10)
    echo(a);

There are no true variables in openscad. They are actually constants and can only have one value at the time the objects are rendered.

To do you want you need: -

sideCenter = isShort ? 115 : 110;





On 27 February 2013 12:40, Joel Bodenmann <[hidden email]> wrote:
I can confirm that this doesn't work on my OpenSCAD version 2013.02.11.


Kind regards,

~ Joel Bodenmann



On 02/27/2013 11:23 AM, Miro Hrončok wrote:
This works for me.


module bearingStand(isShort) {

        if (isShort == true) {
                assign(sideCenter=115);
        }
        else {
                assign(sideCenter=110);
        }
}

(no sideCenter = 100.0)

Miro Hrončok

Jabber: [hidden email]
Telefon: <a href="tel:%2B420777974800" value="+420777974800" target="_blank">+420777974800


2013/2/27 Jeshua Lacock [hidden email]:
Greetings,

I am trying to set a local variable in a module, but I either get a syntax error or if I use "assign" it seems to have no effect.

This is what I have tried:

module bearingStand(isShort) {

        sideCenter = 100.0;

        if (isShort == true) {
                assign(sideCenter = 115);
        }
        else {
                assign(sideCenter = 110);
        }
}

And:

module bearingStand(isShort) {

        sideCenter = 100.0;

        if (isShort == true) {
                sideCenter = 115;
        }
        else {
                sideCenter = 110;
        }
}

Any suggestions would be greatly appreciated!


Thanks,

Jeshua Lacock
Founder/Engineer
3DTOPO Incorporated
<http://3DTOPO.com>
Phone: <a href="tel:208.462.4171" value="+12084624171" target="_blank">208.462.4171

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

Re: Module Variables

Giles Bathgate-2
In reply to this post by Jeshua Lacock
See:

http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Variables_are_set_at_compile-time.2C_not_run-time

By the looks of it, assign won't do what you want either, its a limitation of OpenSCAD.

Regards,
Giles