0
PVector m3()
{ 
  return null;
}

(yup, that's the whole program) gives

Error on "PVector"

enter image description here

Why? It looks legal to me.

The same fail occurs with a different Processing-specific type e.g. color but not with a native type e.g. float.

Workaround:

enter image description here

ChrisJJ
  • 2,191
  • 1
  • 25
  • 38

2 Answers2

1

This is because PVector is a class, not a method. I think if you want to make it return null, you have to add void in the front.

void PVector m3() {
    return null;
}

Unless you want to create a PVector, you simply type it like creating a new object. Here are some examples:

PVector m3 = null;
PVector m1 = new PVector();
PVector m2 = new PVector(2, 3);

For more information on how to use PVector, I suggest you to look at the information posted on the official Processing website. Here is the link: https://processing.org/reference/PVector.html

I hope this answers your question, good luck!

Catherine
  • 99
  • 9
-1

Processing works in two modes:

Static mode is just a bunch of function calls. In this mode, Processing just draws a single image and then stops. Here's an example:

background(32);
ellipse(10, 20, 50, 50);

Active mode is a sketch that contains functions like setup() and draw(). In this mode, Processing continues executing code after the program starts: for example it executes draw() 60 times per second, or mousePressed() when the user presses the mouse. Here's an example:

void draw(){
  background(32);
  ellipse(mouseX, mouseY, 25, 25);
}

The problem with your sketch is that Processing doesn't know which mode you're trying to use. It sees that you don't have a setup() or draw() function (or any other Processing callback function), so it thinks you're trying to use static mode. But then it sees you've defined a non-callback function, so it doesn't know how to work.

Like you've discovered, the solution to your problem is to add other functions, so Processing can know what mode you want to be in. Also note that none of your code makes a ton of sense by itself, because Processing has no way of accessing it. My guess is you're planning on adding setup() and draw() functions eventually, so just add them now to get rid of your error.

For more info:

  • See George's answer here.
  • See my answer here.
  • See this GitHub issue where the creator of Processing explains all of the above.
Kevin Workman
  • 41,537
  • 9
  • 68
  • 107