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

nop head nop.head at gmail.com
Wed Apr 1 06:10:31 EDT 2015


You need the same brackets in cpos() otherwise it does the add before the
?. You also have lots of brackets where you don't need them.

function cpos(s, n) = n == -1 ? 0 : cpos(s,n-1) + (s[n]=="." ? 2 : 4 );

On 1 April 2015 at 11:07, nop head <nop.head at gmail.com> wrote:

> Your last example works if you add some brackets
>
> echo (  0                // n = -1
>         + (s[0]=="."?2:4)  // n = 0 so should be 4
>         + (s[1]=="."?2:4)  // n = 1 so should be 4
>         + (s[2]=="."?2:4)  // n = 2 so should be 2
>         + (s[3]=="."?2:4)  // n = 3 so should be 4
>     ); // Outputs "ECHO: 14"
>
>
> On 1 April 2015 at 10:57, MichaelAtOz <oz.at.michael at gmail.com> wrote:
>
>> BTW you may want to check out  assign() [depricated]
>> <
>> https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Conditional_and_Iterator_Functions#Assign_Statement
>> >
>> and  this.
>> <https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions>
>>
>>
>>
>> -----
>> 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. This work is
>> published globally via the internet. :) 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/
>> --
>> View this message in context:
>> http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12282.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/d07cb7ae/attachment-0002.html>


More information about the Discuss mailing list