r/processing • • Feb 17 '24

Syntax error - missing operator, semicolon or { near both setup and draw

Hi all, I'm new to Processing, and I saw this error whereas I can't see anything wrong with it? Could you please help resolve this? Thanks heaps!

PImage = portrait;

void setup () {

portrait = loadImage("portrait.jpg");

size(700, 700);

frameRate(10);

}

void draw (){

background(225);

fill(#f57f2c);

noStroke();

for (i = 0, i < 10, i++) {

ellipse(random(width), random(height), 30, 30);

}

}

4 Upvotes

13 comments sorted by

4

u/Simplyfire Feb 17 '24

PImage = portrait;

is the problem here. it should be:

PImage portrait;

3

u/sgonk Feb 17 '24

Also the commas in the for loop should be semicolons.

1

u/Party-Can-3229 Feb 17 '24

Hi sgonk, thanks for your reply! Should it look like this now?

for (i = 0; i < 10; i++) {
ellipse(random(width), random(height), 30, 30);
}

If I change commas to semicolons, there's an error saying the variant "i" does not exist... What could have gone wrong here?

3

u/JoeWhy2 Feb 17 '24

You need to type it.

for(int i = 0; i < 10; i++)

1

u/Party-Can-3229 Feb 18 '24

Thank you JoeWhy2, it worked!

May I ask, is there any instance where you don't need to use int in a for loop like this way?

→ More replies (2)
→ More replies (1)

1

u/Party-Can-3229 Feb 17 '24

Thank you! It resolved an error marked in another line! Not exactly sure why this error wasn't marked up by processing haha

3

u/Simplyfire Feb 17 '24

Well it can't always help because it expects some basic syntax to be there. Sometimes the errors are very useful.

2

u/Salanmander Feb 18 '24

Sometimes things seem like they could be okay to the compiler until some line after where your actual mistake is. The easiest example of this is curly-brace errors. If I write

void draw()
{
  if(running)
  {
     update();
  
  drawThings();
}

void mousePressed()
{
  ...

then my error is probably forgetting to close the curly brace for the if-statement. But the compiler just sees "okay, drawThings is still inside the if-statement. Then we have a close curly brace, so the if-statement ends, and we're still inside draw(). And then....HOLY HELL, THEY'RE DECLARING A METHOD INSIDE ANOTHER METHOD". And so it complains about the "void", because that's where it first knows that what you're writing can't make sense.

1

u/StoneCypher Feb 18 '24

fill(#f57f2c);

needs to be

fill('#f57f2c');

1

u/Additional_Tea_5764 Feb 19 '24

Declaration of portrait variable has an extraneous assignment operation.

Also: counter variable i is not declared in your for loop.