0
\$\begingroup\$

So I actually have the following code that works:

var player;
var box_tnt;

function create (){
    this.physics.add.collider(player, box_tnt, hitTnt, null, this);
}

//the function hitTnt stop the game because the player died
function hitTnt (player, boxes){
   this.physics.pause();
   console.log('Game Over!');
   textGameOver.setText('GAME OVER');
   player.setTint(0xff0000);
   player.anims.play('default');
   gameOver = true;
}

and I want to do something like:

var player;
var box_tnt;

function create (){
    this.physics.add.collider(player, box_tnt, hitTnt, null, this);
}

//the function hitTnt stop the game because the player died
function hitTnt (player, boxes){
    gameOver();
    //other stuff here
}

function gameOver (){
    this.physics.pause();
    console.log('Game Over!');
    textGameOver.setText('GAME OVER');
    player.setTint(0xff0000);
    player.anims.play('default');
    gameOver = true;
}

but I have the following error message:

TypeError: gameOver is not a function

Do you have please any ideas how to do it properly?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

gameOver = true; this overwrites gameOver; it used to be a function, now it's a boolean holding true value.

\$\endgroup\$
1
  • \$\begingroup\$ Thank you for making me realise this stupid mistake, know I can access the function that I renamed gameEnd(); but I still have the following error: this.physics is undefined How do I please pass this. and player. from function hitTnt to function gameEnd ? \$\endgroup\$ Commented Feb 10, 2019 at 22:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.