Skip to content

function/variable "does not exist" errors reported if trying to define a class without setup/draw #579

Closed
@processing-bot

Description

@processing-bot

Created by: kjhollen

Description

I was starting a new project and had a mostly empty file as the main PDE, with the exception of an import for the video library. I created a new file to write a class, and all references to Processing functions & variables were red underlined as errors. Error messages were, for example, "mouseX does not exist", despite syntax highlighting picking them up correctly. I was able to make this go away by adding empty setup() and draw() definitions in the main PDE file.

Expected Behavior

A descriptive error suggesting to define setup() and draw() in the appropriate file before defining a class that depends on Processing variables and functions.

Current Behavior

App says library variables and function names like ellipse() and mouseX do not exist.

Steps to Reproduce

  1. Create and save a new sketch
  2. Add a second tab with a name of your choice, in my case it was Button
  3. Define a class in the new tab, referencing some of the Processing functions, but do not add code to the main file

Here's the code used in my second tab that reproduces the error:

class Button {
  
  int x, y, radius;
  
  public Button (int x, int y, int radius) {
    this.x = x;
    this.y = y;
    this.radius = radius;
  }
  
  boolean over() {
    return dist(mouseX, mouseY, this.x, this.y) < this.radius;
  }
  
  void draw() {
    ellipse(this.x, this.y, this.radius * 2, this.radius * 2);
  }
  
}

mouseX, mouseY, and ellipse() will show as errors, hovering/clicking for more detail says "does not exist"

Your Environment

  • Processing version: 4.0.1
  • Operating System and OS version: macOS 12.4 / Apple M1
  • Other information:

Possible Causes / Solutions

Based on what I remember about how Processing parses the main sketch file depending on whether or not setup() or draw() are defined, I think it makes sense that it wouldn't be possible to define a (nested) class without formally defining setup()/draw(). But, initially I thought this was some kind of parsing error and restarted the app to see if it would go away. I'm not suggesting there's a mode of use that justifies defining a class without setup()/draw(), just that a more descriptive error message would be useful when this happens.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions