Making a function call
in
Programming Questions
•
2 years ago
When I write I function, I am only able to call it from setup() or draw(). If I don't call the function from within setup() or draw(), I get an "unexpected token: void" error. What's going on?
For example, the following does not work:
twoLines(10, 10, 50, 70);
void twoLines(int x1, int y1, int x2, int y2) {
line(x1, y1, x2, y2);
line(x1+ 10, y1+10, x2 + 10, y2 + 10);
}
line(x1, y1, x2, y2);
line(x1+ 10, y1+10, x2 + 10, y2 + 10);
}
However, this works:
void draw() {
twoLines(10, 10, 50, 70);
}
twoLines(10, 10, 50, 70);
}
void twoLines(int x1, int y1, int x2, int y2) {
line(x1, y1, x2, y2);
line(x1+ 10, y1+10, x2 + 10, y2 + 10);
}
line(x1, y1, x2, y2);
line(x1+ 10, y1+10, x2 + 10, y2 + 10);
}
I don't understand why. Appreciate any insight.
1