1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Node Box 2: Following code tutorial

Posted by Jimmy Gunawan on Dec 04, 2009

Dear NodeBox Team,

I am following this tutorial on creating your own node:
http://beta.nodebox.net/wiki/NodeBox_for_Programmers
http://beta.nodebox.net/wiki/Writing_Your_Own_Node

I copy & paste the code into Source and reload, but all I got is always this error with X cross mark on the node. I was wondering what I have done wrong. I checked the example file Chrysant and compare it with my file, I don't see any different. I believe I add the Parameters as suggested (for Chrysant).

The script from you guys are working, but not the one I try to make myself.

Any hint?

Sorry for simple question I am very new on this.


 
Posted by lievn on Dec 06, 2009

hi,
could you maybe send the error which should appear when "messages" is turned on?
possible answers might be :
- when copy pasting you should be aware that the indentation is still correct.
- you should start from a generator node which has a star in its icon
- upgrade to the latest version, i havent seen the big X crossmark for a while, errors are now shown by diagonal red stripes.
- if none of this helps, send an error..



Posted by Jimmy Gunawan on Dec 07, 2009

The error message is:
SyntaxError: ("mismatched input '' expecting EOF", ('', 2, 1, ' from math import sin,cos,pi\n'))

1. I think indentation is still there.
2. Yup, that's the one I am using.
3. Latest version... checked. It is shown with diagonal red stripes.

Thanks Lievn.



Posted by Jimmy Gunawan on Dec 07, 2009

Wait...

I looked properly at the code, compare it with the working example, and I think you are right. The code I copy and paste from the website has extra indentation.

It is now working! All I need to do is to get rid of that spacing indentation.

Thank you! Now I know I better type it.



Posted by Jimmy Gunawan on Dec 07, 2009

CORRECTION:

Further comparison, not the indentation that caused this error.

I found that the code on the tutorial is actually different:

### Working Code
from nodebox.graphics import Path
from math import sin,cos,pi

def cook(self):
p = Path()
p.fill = None
x0,y0 = 0.0,0.0
scale = 10.0

for i in xrange(self.number):
u = i * 21.0 * pi / self.number;
p4 = sin(17.0 * u / 3.0);
p8 = sin(2.0 * cos(3.0 * u) - 28.0 * u);
r = self.scale*(1.0 + sin(self.texture*u/5.0)) - 4.0*p4*p4*p4*p4 * p8*p8*p8*p8*p8*p8*p8*p8

x1 = r*cos(u)
y1 = r*sin(u)
p.addPoint(x1, y1)
x0,y0 = x1,y1
return p.asGeometry()


### FAIL CODE

from nodebox.graphics import Path
from math import sin,cos,pi

def cook(self):
p = Path()
p.fill = None
x0,y0 = 0.0,0.0
scale = 10.0

for i in xrange(self.number):
u = i * 14.0 * pi / self.number
p4 = sin(17.0 * u / 3.0) ** 4
p8 = sin(4.0 * cos(3.0 * u) - 28.0 * u) ** 8
r = self.scale*(1.0 + sin(self.texture*u/5.0)) - 14.0*p4 * p8

x1 = r*cos(u)
y1 = r*sin(u)
p.addPoint(x1, y1)
x0,y0 = x1,y1
return p.asGeometry().

Now, when I paste the working code, it just works.

Btw,
** 4 and ** 8 looked very peculiar on the FAIL CODE.

Probably the syntax has issue? I am not familiar with the code, so pardon my cluelessness.

Thanks.



Posted by Jimmy Gunawan on Dec 07, 2009

I found out the culprit. You are right, it is the indentation, after all. I did not know that the code is so picky on spacing.

When I copy-paste the code, the beginning appears like this:

### see the extra spacing ###

from nodebox.graphics import Path
from math import sin,cos,pi
def cook(self):

I get rid of that extra invisible spacing:

from nodebox.graphics import Path
from math import sin,cos,pi
def cook(self):

The code is now working without issue :)

Cheers for pointing this out.

- Jim



Posted by Jimmy Gunawan on Dec 07, 2009

None of the code above will work without indentation. Now it is very clear. Cheers.



Posted by lievn on Dec 08, 2009

hi,
i changed the code blocks on the wiki. you should be able to copy paste code from the website to nodebox without having to worry about indentation level.