Function to add text inside a class

Hello everyone!

I am trying to integrate a method to my class, whose function is to add text.

However, I am getting an error which I am not able to resolve.

My code:

class Options {

    a = this.add.text(200,500, a);
    b = this.add.text(370,500, b);
    c = this.add.text(200,550, c);
    d = this.add.text(370,550, d);


var example = new Options();


And this is the error I get:

The function individually works correctly, but inside a class it gives me an error.


Add scene parameter.

 addText(scene, a,b,c,d){
    a = scene.add.text(200,500, a);
    b = scene.add.text(370,500, b);
    c = scene.add.text(200,550, c);
    d = scene.add.text(370,550, d);

Then call it

example.addText(this, "Text");
1 Like

That’s interesting.

Thank you, rexrainbow!

omg, I had the exact same problem just now!

this helped me as well @rexrainbow :+1:

and thx for asking @dawser95! :100: