a stupid syntax error I can't see

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

a stupid syntax error I can't see

DanS
I obviously have some stupid syntax error that I can't figure out.  I suspect that I need to do something for my if statement that I haven't

I've looked at the manual and my module, if, and for statements look (to me) conformant.  But obviously I've missed something.  The line "angle = " is flagged as being bad, but if I move it above the if statement (or remove the if statement) it goes past that and then has an issue with inside the for loop.

What am I doing wrong?


module rfsphere(counter,geometry,growth,xoffset,yoffset,size)
  {
  if(counter>0)
    {
    angle = (360/geometry);
    ratio = (1 / (geometry / 2));
    newcounter = counter - 1;
    newgeometry = geometry + growth;
          newsize = size * ratio;
    for(i=[1:1:geometry])
      {
      xoffset = xoffset + (size * sin(angle*i);
      yoffset = yoffset + (size * cos(angle*i);
      translate([x,y,0]) {
                   sphere(newsize, $fn=100);
      }
      rfsphere(newcounter, newgeometry, growth, xoffset, yoffset, newsize);
    }
}
Reply | Threaded
Open this post in threaded view
|

Re: a stupid syntax error I can't see

Andrea Croci
Could it be that curly bracket after translate that is not closed?

On 06.08.2016 22:27, DanS wrote:

> I obviously have some stupid syntax error that I can't figure out.  I suspect
> that I need to do something for my if statement that I haven't
>
> I've looked at the manual and my module, if, and for statements look (to me)
> conformant.  But obviously I've missed something.  The line "angle = " is
> flagged as being bad, but if I move it above the if statement (or remove the
> if statement) it goes past that and then has an issue with inside the for
> loop.
>
> What am I doing wrong?
>
>
> module rfsphere(counter,geometry,growth,xoffset,yoffset,size)
>    {
>    if(counter>0)
>      {
>      angle = (360/geometry);
>      ratio = (1 / (geometry / 2));
>      newcounter = counter - 1;
>      newgeometry = geometry + growth;
>  newsize = size * ratio;
>      for(i=[1:1:geometry])
>        {
>        xoffset = xoffset + (size * sin(angle*i);
>        yoffset = yoffset + (size * cos(angle*i);
>        translate([x,y,0]) {
>   sphere(newsize, $fn=100);
>        }
>        rfsphere(newcounter, newgeometry, growth, xoffset, yoffset, newsize);
>      }
> }
>
>
>
> --
> View this message in context: http://forum.openscad.org/a-stupid-syntax-error-I-can-t-see-tp18036.html
> Sent from the OpenSCAD mailing list archive at Nabble.com.
>
> _______________________________________________
> 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: a stupid syntax error I can't see

fred_dot_u
In reply to this post by DanS
The two lines with offset in them, xoffset and yoffset are missing trailing ) and the entire module needs a closing }

I did not test any other aspect other than to identify the syntax problems.
tp3
Reply | Threaded
Open this post in threaded view
|

Re: a stupid syntax error I can't see

tp3
In reply to this post by DanS
On 08/06/2016 10:27 PM, DanS wrote:
> The line "angle = " is flagged as being bad, but if I move it above
> the if statement (or remove the if statement) it goes past that...
>
In addition to the other issues mentioned, are you using an old
version which does not allow assignments everywhere?

ciao,
  Torsten.


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

Re: a stupid syntax error I can't see

DanS
In reply to this post by fred_dot_u
Thanks for picking up those errors. I did not see the missing closing brace or the missing parens.  But even after those are fixed, it oddly still complains that there is a syntax error on the first assignment.  Is something wrong with my "if" syntax?

it still highlights the whitespace character just after "angle =" and says there is a syntax error on that line


module rfsphere(counter,geometry,growth,xoffset,yoffset,size)
  {    
  if(counter>0)
    {
    angle = (360/geometry);
    ratio = (1 / (geometry / 2));
    newcounter = counter - 1;
    newgeometry = geometry + growth;
    newsize = size * ratio;
    for(i=[1:1:geometry])
      {
      xoffset = xoffset + (size * sin(angle*i));
      yoffset = yoffset + (size * cos(angle*i));
      translate([x,y,0])
        {
                   sphere(newsize, $fn=100);
        }
      rfsphere(newcounter, newgeometry, growth, xoffset, yoffset, newsize);
      }
    }
  }  
Reply | Threaded
Open this post in threaded view
|

Re: a stupid syntax error I can't see

Drew Rogge
The use of the variables x and y should be xoffset and yoffset I think.


On 8/6/16 2:54 PM, DanS wrote:

> Thanks for picking up those errors. I did not see the missing closing brace
> or the missing parens.  But even after those are fixed, it oddly still
> complains that there is a syntax error on the first assignment.  Is
> something wrong with my "if" syntax?
>
> it still highlights the whitespace character just after "angle =" and says
> there is a syntax error on that line
>
>
> module rfsphere(counter,geometry,growth,xoffset,yoffset,size)
>    {
>    if(counter>0)
>      {
>      angle = (360/geometry);
>      ratio = (1 / (geometry / 2));
>      newcounter = counter - 1;
>      newgeometry = geometry + growth;
>      newsize = size * ratio;
>      for(i=[1:1:geometry])
>        {
>        xoffset = xoffset + (size * sin(angle*i));
>        yoffset = yoffset + (size * cos(angle*i));
>        translate([x,y,0])
>          {
>   sphere(newsize, $fn=100);
>          }
>        rfsphere(newcounter, newgeometry, growth, xoffset, yoffset, newsize);
>        }
>      }
>    }
>
>
>
> --
> View this message in context: http://forum.openscad.org/a-stupid-syntax-error-I-can-t-see-tp18036p18072.html
> Sent from the OpenSCAD mailing list archive at Nabble.com.
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
Drew Rogge
[hidden email]

Phone: 8934OOO629OO4829631OOOOOOO


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

Re: a stupid syntax error I can't see

fred_dot_u
This post was updated on .
In reply to this post by DanS
I don't get a syntax error or any error message when F5 on the module alone. Calling the module from outside results in an error, because your module contains a call to your module. Should the code you've presented be separated into two distinct segments?

x and y are also undefined.
Reply | Threaded
Open this post in threaded view
|

Re: a stupid syntax error I can't see

DanS
You and Drew pointed out that I'd meant xoffset and written x.

I was just showing the recursive part of my module.

Even after correcting x by chaning it to xoffset (and the same for y) I still get a syntax error on the first assignment (which confuses me).

I'll put all the code here (recursive and non recursive parts), it still flags the "angle =" line as being bad.  Which makes me wonder if my if or module syntax is wrong.

module rfsphere(counter,geometry,growth,xoffset,yoffset,size)
  {    
  if(counter>0)
    {
    angle = (360/geometry);
    ratio = (1 / (geometry / 2));
    newcounter = counter - 1;
    newgeometry = geometry + growth;
    newsize = size * ratio;
    for(i=[1:1:geometry])
      {
      xoffset = xoffset + (size * sin(angle*i));
      yoffset = yoffset + (size * cos(angle*i));
      translate([xoffset,yoffset,0])
        {
                   sphere(newsize, $fn=100);
        }
      rfsphere(newcounter, newgeometry, growth, xoffset, yoffset, newsize);
      }
    }
  }

module fsphere(counter,geometry,growth,size){
        sphere(size, $fn=100);
        counter = counter - 1;
   newsize = (1 / (geometry/2))*size;

   angle = 360/geometry;
   ratio = 1 / (geometry / 2);
   newgeometry = geomertry + growth;
   for(i=steps(1,1,geometry)) {
           x = size * sin(angle*i);
      y = size * cos(angle*i);
      translate([x,y,0]) {
                   sphere(size*scale, $fn=100);
      }
      rfsphere(counter, newgeometry, growth, x, y, size*scale);
    }
}

fsphere(4,3,2,100);
Reply | Threaded
Open this post in threaded view
|

Re: a stupid syntax error I can't see

Whosawhatsis
You can't do assignments inside a conditional in openscad. It's part of the fact that openscad variables aren't really variables. You're also changing the values of variables later, which isn't allowed either.

You can do conditional variable assignment using the ternary operator, but for this purpose, it doesn't look like it's necessary, just set your variables before going into the if statement. Getting rid of the reassignments will be a little more complicated.



From: DanS [hidden email]
Reply: OpenSCAD general discussion [hidden email]
Date: August 6, 2016 at 15:11:04
To: [hidden email] [hidden email]
Subject:  Re: [OpenSCAD] a stupid syntax error I can't see

You and Drew pointed out that I'd meant xoffset and written x.

I was just showing the recursive part of my module.

Even after correcting x by chaning it to xoffset (and the same for y) I
still get a syntax error on the first assignment (which confuses me).

I'll put all the code here (recursive and non recursive parts), it still
flags the "angle =" line as being bad. Which makes me wonder if my if or
module syntax is wrong.

module rfsphere(counter,geometry,growth,xoffset,yoffset,size)
{
if(counter>0)
{
angle = (360/geometry);
ratio = (1 / (geometry / 2));
newcounter = counter - 1;
newgeometry = geometry + growth;
newsize = size * ratio;
for(i=[1:1:geometry])
{
xoffset = xoffset + (size * sin(angle*i));
yoffset = yoffset + (size * cos(angle*i));
translate([xoffset,yoffset,0])
{
sphere(newsize, $fn=100);
}
rfsphere(newcounter, newgeometry, growth, xoffset, yoffset, newsize);
}
}
}

module fsphere(counter,geometry,growth,size){
sphere(size, $fn=100);
counter = counter - 1;
newsize = (1 / (geometry/2))*size;

angle = 360/geometry;
ratio = 1 / (geometry / 2);
newgeometry = geomertry + growth;
for(i=steps(1,1,geometry)) {
x = size * sin(angle*i);
y = size * cos(angle*i);
translate([x,y,0]) {
sphere(size*scale, $fn=100);
}
rfsphere(counter, newgeometry, growth, x, y, size*scale);
}
}

fsphere(4,3,2,100);



--
View this message in context: http://forum.openscad.org/a-stupid-syntax-error-I-can-t-see-tp18036p18075.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
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: a stupid syntax error I can't see

DanS
Thanks, that gets rid of those syntax errors and I'll try to remember no assignments inside if statements.
Reply | Threaded
Open this post in threaded view
|

Re: a stupid syntax error I can't see

Drew Rogge
What version of OpenSCAD are you using? The following works on version 2015.03-1 on a Mac:

module rfsphere(counter,geometry,growth,xoffset,yoffset,size)
   {
   if(counter>0)
     {
     angle = (360/geometry);
     ratio = (1 / (geometry / 2));
     newcounter = counter - 1;
     newgeometry = geometry + growth;
     newsize = size * ratio;
     for(i=[1:1:geometry])
       {
       xoffset = xoffset + (size * sin(angle*i));
       yoffset = yoffset + (size * cos(angle*i));
       translate([xoffset,yoffset,0])
         {
            sphere(newsize, $fn=100);
         }
       rfsphere(newcounter, newgeometry, growth, xoffset, yoffset, newsize);
       }
     }
   }

rfsphere(5, 1, 2, 3, 4, 5);


On 8/6/16 3:27 PM, DanS wrote:

> Thanks, that gets rid of those syntax errors and I'll try to remember no
> assignments inside if statements.
>
>
>
> --
> View this message in context: http://forum.openscad.org/a-stupid-syntax-error-I-can-t-see-tp18036p18077.html
> Sent from the OpenSCAD mailing list archive at Nabble.com.
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
Drew Rogge
[hidden email]

Phone: 8934OOO629OO4829631OOOOOOO


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

Re: a stupid syntax error I can't see

DanS
2014.03

I should probably update
Trying to debug it as it isn't doing what I wanted (found a bunch of mistakes so far, recursion is always messy though).
Reply | Threaded
Open this post in threaded view
|

Re: a stupid syntax error I can't see

Drew Rogge
Yeah, upgrading would be a good thing. I think you could do what you're trying to do by using the
"assign" statement in the version you're using. The assign statement has been deprecated in later versions so it's probably best to not start using it.


On 8/6/16 4:16 PM, DanS wrote:

> 2014.03
>
> I should probably update
> Trying to debug it as it isn't doing what I wanted (found a bunch of
> mistakes so far, recursion is always messy though).
>
>
>
> --
> View this message in context: http://forum.openscad.org/a-stupid-syntax-error-I-can-t-see-tp18036p18079.html
> Sent from the OpenSCAD mailing list archive at Nabble.com.
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
Drew Rogge
[hidden email]

Phone: 8934OOO629OO4829631OOOOOOO


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

Re: a stupid syntax error I can't see

DanS
After debugging I can get fractals and quazi fractals out of the code.  Some of them look rather odd: