Help with sprite

Hello, im trying to call an function when i press a button in html and it throw me this error:

Uncaught TypeError: Cannot read property ‘sprite’ of undefined
at showMessage (init.js:105)
at xd(init.js:121)
at HTMLDivElement.onclick ((index):1)

The function is this:

function xd(){
console.log(“clicked0”);
showMessage();
console.log(“clicked1”);
}

function showMessage(){
this.add.sprite(725, 275, ‘message’);
}

thanks

you should pass the scene object explicitly to the function. you can add console.log(this) inside the showMessage function and check what you are referring to.

You might wanna check on this phaser-v3-example

extending functions to scene