Pass the sketchname like a final

I try to pass my sketch name like a final but i don’t find a way to do that, is it possible ?
sketch name in my case is call_class_itself.pdebut I try to find something more universel.

void setup() {
  println(this.getClass().getSimpleName());
}

import rope.costume.R_Shape;
public class Test extends rope.costume.R_Shape { 
  final call_class_itself me;
  // here the purpose to mke something universel
  // final this.getClass().getSimpleName() me;
  Test(PApplet pa) {
    super(pa);
    me = (call_class_itself) pa;
    
  }
  
  void truc(PApplet pa) { 
    me.beginShape(other);
  }
}

void beginShape(PGraphics other) {
}

see topic : https://forum.processing.org/two/discussion/14943/how-do-you-call-a-method-in-your-main-sketch-from-a-class-with-arguments

beginShape() is a PApplet method:
Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#beginShape--

Therefore, field me doesn’t need to be of derived datatype call_class_itself in order to access the beginShape() member.

A me field of parent datatype PApplet would be just enough.

Java demands that all datatypes of its variables & functions to be already known at compile time, before the program is even run.

What you’re attempting to do above is to dynamically declare a field named me w/ some datatype that’s still gonna be determined in the future at run time, when the program’s already been compiled & running.

Most Java can offer at run time is what is called reflection or introspection:
Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/reflect/package-summary.html

So we can attempt to access members of an object outside its apparent datatype.

Maybe I’m not clear, I write my custom Processing method like beginShape(Pgraphics pg) and when I try to call this one from a class write outside Processing, my sketch don’t find it and return an error, it’s reason why i need to call those methodes from the sketch, and if I want something universal I cannot write the sketch name directly, I need to something to finf the sketchname before… its clearest ?

beginShape(other); -> Where is that field other declared & initialized? :confused:

You point the problem this one is from rope.costume.R_Shape the library. So it’s a reason why my little class don’t want read the method beginShape(PGraphics other)

What’s the name of that library? Where can I get it? :cowboy_hat_face:

it’s my little library the link is here :slight_smile: https://github.com/StanLepunK/Rope

(remark: a small sketch to show the sketch name: )


String sketchName1;

void setup() {
  size(600, 600);
  background(0); 

  sketchName1 = this.getClass().getSimpleName();

  println(sketchName1);
}

void draw() {
  //
  background(0);
  text(sketchName1, 30, 30);
}
//

thx but, I know that it’s the first line of my code println(this.getClass().getSimpleName());my problem is transforme that in final this.getClass().getSimpleName() me; and that’s cannot be a String.

1 Like

What do you mean by write (or written?) outside Processing? :writing_hand:

Do you mean a “.java” file by any chance? :thinking:

B/c inside “.pde” files, the example below compiles OK: :ok_hand:

void setup() {
  exit();
}

void beginShape(PGraphics other) {
}

class Test {
  PGraphics other;

  void truc(PApplet pa) {
    beginShape(other);
  }
}

I written :slight_smile: outside to mean the class parent is in a library. And in this case the class child cannot read the similar method write in the sketch like beginShape(PGraphics other).

I’ve just expanded my previous minimum “.pde” example to include a “.java” file as well: :coffee:

sketch_190529a.pde:

void setup() {
  new Test();
  exit();
}

void beginShape(PGraphics other) {
}

class Test extends rope.costume.R_Shape {
  void truc(PApplet pa) {
    beginShape(other);
  }
}

R_Shape.java:

package rope.costume;

import processing.core.PGraphics;

public class R_Shape {
  public PGraphics other;
}

Like my previous example w/ just 1 “.pde” file, this 1 w/ both “.pde” & “.java” + extends compiles successfully as well. :partying_face:

Can you also provide us a minimum runnable sketch that demos the compile error you’re getting? :face_with_thermometer:

1 Like

I cannot do more simple what I passed before, maybe the error is from dial between processing and library I suppose…are you try with my library ?

See the screen-shot above

All my minimum runnable sketches have been based on your screenshot code! :roll_eyes:

But to prove once again your compile error doesn’t show up at all, here’s a “.pde” file exactly like your screenshot: :copyright:

call_class_itself.pde:

void setup() { }

import rope.costume.R_Shape;
class Test extends rope.costume.R_Shape {
  Test(PApplet pa) {
    super(pa);
  }

  void truc(PApplet pa) {
    beginShape(other);
  }
}

void beginShape(PGraphics other) {
}

And 3 minimum compilable “.java” files based (as much as I could) on your 3 original classes R_Shape, R_Image & BigBang from your library, following up all their inheritance chain: :coffee:

R_Shape.java:

package rope.costume;

import rope.core.*;
import processing.core.*;

public class R_Shape extends R_Image {
  public R_Shape(PApplet pa) {
    super(pa);
  }

  public R_Shape(PApplet pa, PGraphics other) {
    super(pa, other);
  }
}

R_Image.java:

package rope.core;

import processing.core.*;

public class R_Image extends BigBang {
  protected processing.core.PGraphics other;

  public R_Image(PApplet pa) {
    super(pa);
  }

  public R_Image(PApplet pa, PGraphics other) {
    super(pa);
    this.other = other;
  }
}

BigBang.java:

package rope.core;

import processing.core.*;

public abstract class BigBang {
  public PApplet pa;

  public BigBang() {
  }

  public BigBang(PApplet pa) {
    this.pa = pa;
  }
}

Unless you could come up w/ some actually runnable code like mine above, that proves your compilable error does happen, I can’t help you anymore, sorry. :confounded:

1 Like