Delay before switching scenes - Cannot read properties of undefined 'queueOp'

Hello,

I’m making a little RPG game. I followed the tutorial from gamedevacademy. The errors I’m having would apply to their code (though I have modified it).

When the player sprite overlaps with an enemy zone (with sprite), the onMeetEnemy function triggers, including the following code:

onMeetEnemy(player, zone){

    //camera shake
    this.cameras.main.shake(300);

   //start battle
   this.time.delayedCall(500, this.scene.switch, ['BattleScene'], this);
}

Currently, the camera shakes only after the player has left the battle scene.

If I try to change it to add any sort of delay, like so:

this.time.delayedCall(500, this.scene.switch, ['BattleScene'], this);

or

this.time.delayedCall(500, this.switchBattle, this); //inside onMeetEnemy

switchBattle(){ //a function of my Scene
    this.scene.switch('BattleScene');
}

After the delay, I get an error in devtools:

Uncaught TypeError: Cannot read properties of undefined (reading 'queueOp')

at phaser.js?d4ef:199370, which appears to be part of ScenePlugin


    switch: function (key)
    {
        if (key !== this.key)
        {
            this.manager.queueOp('switch', this.key, key);
        }

        return this;
    },

Maybe there’s a better way to do a delay like this?

github here doublespoiler/RPG-1 (github.com)

I think that should be

this.time.delayedCall(500, this.scene.switch, ['BattleScene'], this.scene);

I think that should be

this.time.delayedCall(500, this.switchBattle, [], this);