Problems with syntax
in
Programming Questions
•
2 years ago
Hi there,
I recently started working through the Processing examples in a book called "Programming Interactivity" by Joshua Noble. It's an excellent book but unfortunately there seem to be a lot of typos (the errata is rapidly becoming as long as the book).
The code example reads as follows:
class Point{
float x;
float y;
Point(float _x, float _y){
x = _x;
y = _y;
}
Point[] pts = new Point[6];
int count = 0;
void setup(){
size(500, 500);
}
void draw(){
background(255);
fill(0);
beginShape();
for(int i = 0; i<pts.length; i++){
if(pts[i] != null{
vertex(pts[i].x, pts[i].y);
}
}
endShape();
}
void mousePressed(){
if(count > 5){
count = 0;
}
Point newPoint = new Point(mouseX, mouseY);
pts[count] = newPoint;
count++;
}
class Point{
float x;
float y;
Point(float _x, float _y){
x = _x;
y = _y;
}
}
The error Processing throws up is "unexpected token: null".
Thanks in advance for any help.
I recently started working through the Processing examples in a book called "Programming Interactivity" by Joshua Noble. It's an excellent book but unfortunately there seem to be a lot of typos (the errata is rapidly becoming as long as the book).
The code example reads as follows:
class Point{
float x;
float y;
Point(float _x, float _y){
x = _x;
y = _y;
}
Point[] pts = new Point[6];
int count = 0;
void setup(){
size(500, 500);
}
void draw(){
background(255);
fill(0);
beginShape();
for(int i = 0; i<pts.length; i++){
if(pts[i] != null{
vertex(pts[i].x, pts[i].y);
}
}
endShape();
}
void mousePressed(){
if(count > 5){
count = 0;
}
Point newPoint = new Point(mouseX, mouseY);
pts[count] = newPoint;
count++;
}
class Point{
float x;
float y;
Point(float _x, float _y){
x = _x;
y = _y;
}
}
The error Processing throws up is "unexpected token: null".
Thanks in advance for any help.
1