I’m getting back into coding after 20 some years… I’ve been toying around with processing for a year now, doing simple things… but this time, I want to learn classes
I have followed this tutorial Objects by Daniel Shiffman on Processing site worked well. until now…
I ran into a a problem that I just can’t figure out.
What I want to do
Control 3 different VLC player on different computer. Works flawless with “regular” code.
I decided to create a class to “clean” the code instead of having 3 time the same code for each instance different VLC player.
I hope it make sense, thanks for taking the time to help out…
Eric
error at compile
The constructor Client (VLC_Class.VLC, String, int) is undefined
The problem is that when you were setting up the client inside setup(), the keyword this used in the constructor refered to the PApplet that setup() belongs to. Once you moved this constructor call for Client() inside your class, the this keyword now refers to that class, and not the PApplet that it was referencing before.
The solution is to pass the reference to your PApplet into your own constructor:
// inside setup():
vlc1 = new VLC(this, "127.0.0.1", 4212, "1234");
// Fix your class to deal with the new parameter:
Client client;
PApplet parent_app;
VLC( PApplet ipa, String tempIP, int tempPort, String tempPass) {
parent_app = ipa;
serverIP = tempIP;
portNumber = tempPort;
password = tempPass;
}
void connect() {
println("connect");
client = new Client(parent_app, serverIP, portNumber); // The this that was here was the problem - now changed.
client.write(password+enter);
}
You could also have added a global variable to store this reference to the parent PApplet in setup and use it inside your class, should you not desire to pass it as a parameter.
@EricSaumier – Using a global variable certainly an option, but the first pattern that @TfGuy44 recommends – passing in a PApplet with this – is very standard in Processing. Many of the major libraries follow this pattern, and require you to initialize a major library object with this in order to work their magic (see ControlP5, G4P, PeasyCam, etc etc). For example, you fire up ControlP5 with:
I took the time to digest everything… I’m starting to understand things a bit more, and it starts make sense. I need to really undestand PApplet… with GoToLoop link, I think i’m on the right path…
Thanks alot for the help and the time you guys invest helping others. One day, I’ll give back!
@TfGuy44 … I tested your "untested’ solution… worked on first try. @jeremydouglass That will be the way I’ll go… seems to make more sense