# Pass the sketchname like a final

**URL:** https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654
**Category:** Libraries
**Created:** [May 28, 2019, 9:27am UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654 "2019-05-28T09:27:32Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)
#### Post date: [May 28, 2019, 9:27am UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/1 "2019-05-28T09:27:32Z")

</div>

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.pde`but I try to find something more universel.

```auto
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](https://forum.processing.org/two/discussion/14943/how-do-you-call-a-method-in-your-main-sketch-from-a-class-with-arguments)

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 28, 2019, 10:30am UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/2 "2019-05-28T10:30:28Z")

</div>

> [@Stanlepunk](#):
>
> `me.beginShape(other);`

**beginShape()** is a PApplet method:  
[Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#beginShape--](http://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.

> [@Stanlepunk](#):
>
> `final this.getClass().getSimpleName() me;`

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](http://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.

---

<div class="post-metadata">

### Author: ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)
#### Post date: [May 28, 2019, 10:43am UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/3 "2019-05-28T10:43:26Z")

</div>

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 ?

 ![45](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a95dd3cd00b59182e1d3d88dd3cd086fd4660131.png)

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 28, 2019, 11:01am UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/4 "2019-05-28T11:01:55Z")

</div>

`beginShape(other);` -\> Where is that field _other_ declared & initialized? 😕

---

<div class="post-metadata">

### Author: ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)
#### Post date: [May 28, 2019, 11:03am UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/5 "2019-05-28T11:03:27Z")

</div>

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)`

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 28, 2019, 11:14am UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/6 "2019-05-28T11:14:19Z")

</div>

> [@Stanlepunk](#):
>
> … this one is from `rope.costume.R_Shape`, the library.

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

---

<div class="post-metadata">

### Author: ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)
#### Post date: [May 28, 2019, 11:28am UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/7 "2019-05-28T11:28:43Z")

</div>

it’s my little library the link is here 🙂 [https://github.com/StanLepunK/Rope](https://github.com/StanLepunK/Rope)

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [May 28, 2019, 12:26pm UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/8 "2019-05-28T12:26:59Z")

</div>

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

```auto

String sketchName1;

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

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

  println(sketchName1);
}

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

```

---

<div class="post-metadata">

### Author: ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)
#### Post date: [May 28, 2019, 1:03pm UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/9 "2019-05-28T13:03:02Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 28, 2019, 6:22pm UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/10 "2019-05-28T18:22:21Z")

</div>

> [@Stanlepunk](#):
>
> … and when I try to call this one from a class write outside Processing,

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

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

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

```auto
void setup() {
  exit();
}

void beginShape(PGraphics other) {
}

class Test {
  PGraphics other;

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

```

---

<div class="post-metadata">

### Author: ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)
#### Post date: [May 29, 2019, 7:30am UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/11 "2019-05-29T07:30:26Z")

</div>

I written 🙂 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)`.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 29, 2019, 4:05pm UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/12 "2019-05-29T16:05:24Z")

</div>

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

## sketch\_190529a.pde:

```auto
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:

```auto
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. 🥳

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

---

<div class="post-metadata">

### Author: ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)
#### Post date: [May 29, 2019, 6:06pm UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/13 "2019-05-29T18:06:51Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)
#### Post date: [May 29, 2019, 6:11pm UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/14 "2019-05-29T18:11:24Z")

</div>

> [@GoToLoop](#):
>
> Can you also provide us a minimum runnable sketch that demos the compile error you’re getting?

See the screen-shot above

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 29, 2019, 6:43pm UTC](https://discourse.processing.org/t/pass-the-sketchname-like-a-final/11654/15 "2019-05-29T18:43:57Z")

</div>

> [@Stanlepunk](#):
>
> See the screen-shot above

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

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

## call\_class\_itself.pde:

```auto
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: ☕

## R\_Shape.java:

```auto
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:

```auto
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:

```auto
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. 😖
