discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

a stupid syntax error I can't see

D
DanS
Sat, Aug 6, 2016 8:27 PM

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(anglei);
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.

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.
AC
Andrea Croci
Sat, Aug 6, 2016 8:32 PM

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(anglei);
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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
F
fred_dot_u
Sat, Aug 6, 2016 8:33 PM

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.

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

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. -- View this message in context: http://forum.openscad.org/a-stupid-syntax-error-I-can-t-see-tp18036p18038.html Sent from the OpenSCAD mailing list archive at Nabble.com.
TP
Torsten Paul
Sat, Aug 6, 2016 8:45 PM

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.

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.
D
DanS
Sat, Aug 6, 2016 9:54 PM

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(anglei));
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.

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.
DR
Drew Rogge
Sat, Aug 6, 2016 9:59 PM

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(anglei));
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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
Drew Rogge
drew@dasrogges.com

Phone: 8934OOO629OO4829631OOOOOOO

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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Drew Rogge drew@dasrogges.com Phone: 8934OOO629OO4829631OOOOOOO
F
fred_dot_u
Sat, Aug 6, 2016 9:59 PM

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?

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

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? -- View this message in context: http://forum.openscad.org/a-stupid-syntax-error-I-can-t-see-tp18036p18073.html Sent from the OpenSCAD mailing list archive at Nabble.com.
D
DanS
Sat, Aug 6, 2016 10:10 PM

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(anglei));
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(anglei);
y = size * cos(angle
i);
translate([x,y,0]) {
sphere(sizescale, $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.

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.
W
Whosawhatsis
Sat, Aug 6, 2016 10:17 PM

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 tabbydan@gmail.com tabbydan@gmail.com
Reply: OpenSCAD general discussion discuss@lists.openscad.org
discuss@lists.openscad.org
Date: August 6, 2016 at 15:11:04
To: discuss@lists.openscad.org discuss@lists.openscad.org
discuss@lists.openscad.org
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(anglei));
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(anglei);
y = size * cos(angle
i);
translate([x,y,0]) {
sphere(sizescale, $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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <tabbydan@gmail.com> <tabbydan@gmail.com> Reply: OpenSCAD general discussion <discuss@lists.openscad.org> <discuss@lists.openscad.org> Date: August 6, 2016 at 15:11:04 To: discuss@lists.openscad.org <discuss@lists.openscad.org> <discuss@lists.openscad.org> 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 Discuss@lists.openscad.org http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
D
DanS
Sat, Aug 6, 2016 10:27 PM

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.

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.