Does anyone know why this occurs?

Hello,
does anyone know how to fix this? Am I building it wrong?
image

create(){
 this.morcego = new Morcego(this)
 this.listaDeSkills.add(new InfoSkill(this, 'morcego', 1, '', this.bat.dano , this.bat.cdr/1000 + 's'))

}
levelUp(){
 console.log(this.listaDeSkills.getChildren().length)
                    for (var i = 0 ; i <this.listaDeSkills.getChildren().length ; i++){
                        var skill = this.listaDeSkills.getChildren()[i]
  if(skill.nome == 'morcego'){
                          this.morcego.levelup()
                          skill.dano = this.bat.dano + 7
                          skill.level = this.bat.level++
                          skill.cdr = (this.bat.cdr - 100)/1000
                          console.log(skill.dano)
                          console.log(skill.level)
                          console.log( skill.cdr)
                          break
  }
}
}
class InfoSkill extends Phaser.GameObjects.Sprite{
    constructor (scene, nome, level, desc, dano, cdr){

        super(scene, nome, level, desc, dano, cdr);
        scene.add.existing(this);
        
        this.nome = nome
        this.level = level
        this.desc = desc
        this.dano = dano
        this.cdr = cdr
    }
     
}
class Morcego extends Phaser.GameObjects.Sprite{
    constructor (scene){

        super(scene);
        scene.add.existing(this);
        
         //bat
         scene.bat = scene.add.group()
         scene.bat.cdr = 2000
         scene.bat.dano = 10
         scene.bat.desenho = 'batskill'
         scene.bat.animacao = 'batskillanim'
         scene.bat.destruir = true
         scene.bat.velocidade = 250
         scene.bat.level = 1
         scene.bat.estagio = 1
         this.iniciar = ()=>{
             //cdr disparo
         this.timer = scene.time.addEvent({
            delay: scene.bat.cdr,                // ms
            callback: scene.usaSkillBat,
            args: [],
            callbackScope: scene,
            loop: true
        });
         }
         this.levelup = ()=>{
            scene.bat.level++
            this.destruir()
            scene.bat.cdr = scene.bat.cdr - 100
            scene.bat.dano+=7
            scene.bat.velocidade+=2
            if(scene.bat.level == 3){
                console.log('a')
                scene.bat.estagio = 2
            } else if(scene.bat.level == 6){
                scene.bat.estagio = 7
                console.log('b')
            }
            this.iniciar()
        }
        this.destruir = ()=>{
            this.timer.destroy()
        }
    }
}

Suppose I select Skill A and then Skill B melts and I can get any other skill including A, so the code follows normally, but if I get A and then A again, I get an error. So if I repeat the same skill 2x it causes this error. It doesn’t make any sense.
Thanks!!

I think this.morcego.iniciar() isn’t getting called.

1 Like

Hello, I call the end of levelup(). Could this be the problem then? If this is the case I can do it manually. I will test here.

it worked in the manual method (destroying and creating outside of leveluo()), but it worked, thank you very much!