Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
processing-bot opened this issue Oct 19, 2022 · 6 comments

Comments

@processing-bot
Copy link
Collaborator

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.

@processing-bot
Copy link
Collaborator Author

Created by: benfry

Did this work properly in 3.x?

(Paging @sampottinger for possible preproc solutions…)

@processing-bot
Copy link
Collaborator Author

Created by: sampottinger

Thanks very much for this bug report @kjhollen.

Hey @benfry! I’ve got this. Working on a PR now.

@processing-bot
Copy link
Collaborator Author

Created by: sampottinger

Thanks for your patience and detailed bug report @kjhollen! Really appreciate it. Just submitted a PR via #597!

@processing-bot
Copy link
Collaborator Author

Created by: kjhollen

Thanks @sampottinger!

@processing-bot
Copy link
Collaborator Author

Created by: benfry

Merged for 4.0.2; thanks Sam.

@processing-bot
Copy link
Collaborator Author

Created by: github-actions[bot]

This issue has been automatically locked. To avoid confusion with reports that have already been resolved, closed issues are automatically locked 30 days after the last comment. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant