Using animation repeat with variable as value

I’m trying to modify the standard looping animation example (Phaser - Examples - Create Animation From Sprite Sheet) so that I can use a variable to control the number of times the animation loops.

I have tried two different ways to do this:

this.anims.create({
            key: 'walk',
            frames: this.anims.generateFrameNumbers('brawler', { frames: [ 0, 1, 2, 3 ] }),
            frameRate: 8,
            repeat: 7
        });
const cody = this.add.sprite(400, 300);
cody.setScale(2);
cody.play('walk');

and

this.anims.create({
            key: 'walk',
            frames: this.anims.generateFrameNumbers('brawler', { frames: [ 0, 1, 2, 3 ] }),
            frameRate: 8,
        });
const cody = this.add.sprite(400, 300);
cody.setScale(2);
cody.play({key: 'walk', repeat: 7});

In both cases, the animation will loop according to the value (7 in both examples). However, if I replace ‘7’ with a variable that is equal to 7, it will only loop once.

Is there a better way to handle this?

Thanks!

Should work. Show how you use the variable.

Thanks! In trying to reply to your answer I figured it out. I had been converting the variable into text just to display it on the screen (and make sure the value carried over). Instead of using the actual variable for the repeat value I was using the variable that held the text.