Unexpected token int (complete noob)

edited September 2016 in Programming Questions

Hi!

I started with Processing like 10 minutes before writing this. I wanted to make a quick sketch as a VERY simple exercise and I'm getting an error that I just don't get.

Here's the code:

int color = 0; void setup() { size(640, 480); } void draw() { if (color<255) { color=color+1; } else { color=0; } if (mousePressed) { fill(color); ellipse(mouseX, mouseY, 40, 40); } }

Processing keeps telling me an "Unexpected token int" error at line 1 but I honestly can't see what's wrong with it.

Thanks in advance! Joan

edit: the forum keeps moving my code lines for some reason. I promise identation is ok.

Tagged:

Answers

  • Answer ✓

    Ok, I figured it out. "color" can't be used as a variable name!

    As I said: complete noob

  • Answer ✓

    Yeah, it's a reserved word as they use it as a (pseudo)type. The only hint you get is a bit of highlighting in the editor. Easy mistake to make 8)

  • If a function or variable line is giving you trouble in the Processing IDE and the error message isn't helping, try right-clicking on the specific word (e.g. color) -- if it offers to let you look it up in the reference or shows usage, that will clarify things -- even if you don't already know all the reserved keywords.

Sign In or Register to comment.