Please a bit of guidence would be appreciated

Hi all I’m starting with phaser, and as a first project I wanted to create a small idler game, the only tutorial I found is this one Phaser Tutorial I found this is the code that Im stuck at as I believe this code was created on an older version f phaser, this is the code:
I keep getting this error: Uncaught TypeError: this.state is undefined and Im not really sure what to look at, could anyone please help me? the error is on this line: monster = state.monsters.create(1000, state.game.world.centerY, data.image);

Full code below:

`var monster;
monsterData.forEach(function(data) {
// create a sprite for them off screen
monster = state.monsters.create(1000, state.game.world.centerY, data.image);
// center anchor
monster.anchor.setTo(0.5);
// reference to the database
monster.details = data;

//enable input so we can click it!
monster.inputEnabled = true;
monster.events.onInputDown.add(state.onClickMonster, state);

});`

Hi,
It seems this tutorial is for Phaser 2, not Phaser 3.

It seems odd that the error says ‘this.state’, which should not be used. Did you change the code?

var state = this;

‘this.state’ would mean ‘this.this’…

Hi @Clooloo ,
@BlunT76 is right. The tutorial you have seen is for Phaser 2.

Thanks this lead me to start rewriting things :slight_smile:

1 Like