We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everyone. I am here with yet another problem, hoping for your help. I've recently started using Eclipse for my Processing project because the number of classes started exceeding the available tabs in Processing app.
So I've got a question about classes. Let's say I have an object of another class created inside my main class, also there is a boolean variable:
import processing.core.PApplet;
public class MainClass extends PApplet {
MyClass obj;
boolean variable;
public static void main(String[] args) {
PApplet.main("MainClass");
}
public void settings() {
size ( 1280, 720);
}
public void setup() {
obj = new MyClass(this);
}
public void draw() {
}
}
Then there is another class which, if it was created in Processing app, would see both "obj" and "variable", but in Eclipse it doesn't recognise them:
import processing.core.PApplet;
public class AnotherClass{
PApplet parent;
public AnotherClass( PApplet p) {
parent = p;
}
void update() {
variable = true;
obj.doSomething();
}
}
How can I, in a not very complicated way, make "AnotherClass" recognise both " obj" and "variable" in a similar manner to how it happens in Processing app? Thanks in advance!
Answers
If the classes are in the same package then this should work
This solution does make sense to me, but it doesn't work with my setup for some reason. Here is what I get:
console:
Code:
.
operator: https://Processing.org/reference/dot.html@GoToLoop, using the dot operator is fine as long as it works. I am having a problem with it though, please, check my post above.
@GotoLoop is right they are members of MainClass not PApplet so my solution is not a solution at all.
Correct me if I am wrong, but for a class to be nested in another class, it needs to be in the same class file. It's a bit of a problem for me because I would like to have multiple class files.
(MainClass)
. :ar!It did work when instead of referencing PApplet I referenced MainClass. Yay! Thank you for your help!