[OpenSCAD] Incrementing a variable doesn't work as expected.

nop head nop.head at gmail.com
Wed Apr 1 04:32:03 EDT 2015


You can't modify variables, so not only is inc out of scope but you can't
change the value of pos.

Recursion is the right way to do it but you have infinite recursion because
you unconditionally call cpos(s,n-1).

On 1 April 2015 at 08:44, nigeljohnson73 <nigel at nigeljohnson.net> wrote:

> For info, here is my recursive position counter that fails:
>
> function cpos(s, n) = cpos(s,n-1) + (n == -1) ? (0) : ( (s[n]==".") ? 2 :
> 4);
>
> when I use it instead of pos in the x coordinate for example in the dit:
>
> translate([cpos(s,i)+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2);
>
> it says recursion detected. It's not lying  but the manual says I can do
> recursion with the trigraph stuff.
>
>
>
>
>
> --
> View this message in context:
> http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12272.html
> Sent from the OpenSCAD mailing list archive at Nabble.com.
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss at lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20150401/e7b4a188/attachment-0002.html>


More information about the Discuss mailing list