[SOLVED] Playing 3 slots in sequence, but only the last one is played

I’m trying to reproduce the sound effect of a pistol reload split into 3 slots (Pistol Mag Drop, Pistol Mag Input and Pistol Mag Lock) that triggers when I press the R button, but only the last slot plays. Does anyone have a suggestion on how I can solve this problem?

Project link:
https://playcanvas.com/project/971986/overview/play-slots

Hello Mesquita1991! Welcome to to the PlayCanvas forums.

I’ve taken a look at your project, and all 3 sounds seem to be playing simultaneously as expected. If you’re still unsure, I suggest you add this to your reload script to test it and compare the sounds - they’re very similar.

// update code called every frame
Weapon.prototype.update = function(dt) {
    if (this.app.keyboard.wasPressed(pc.KEY_R)) {
        this.reload();
    }

    if (this.app.keyboard.wasPressed(pc.KEY_B)) {
        this.test();
    }
};

Weapon.prototype.reload = function() {
    this.entity.sound.play('Pistol Mag Drop');
    this.entity.sound.play('Pistol Mag Input');
    this.entity.sound.play('Pistol Mag Lock');
};

Weapon.prototype.test = function() {
    this.entity.sound.play('Pistol Mag Lock');
};
1 Like

Hey Mesquita, I’m also attaching a link on how the Sound component works. The way you are calling play in the code will cause the sounds to play simultaneously. This is by design. You might want to take a look at the setTimeout function, which can add a delay between specific actions in a script.

Hello, poliveira! Thank you so much for the answers and for taking the time to help me. I solved my problem following your suggestion:

this.entity.sound.play('Pistol Mag Drop');
setTimeout(() => {
    this.entity.sound.play('Pistol Mag Input');
}, 1220);
setTimeout(() => {
    this.entity.sound.play('Pistol Mag Lock');
}, 1730);