Sound being play twice randomly - bug or I'm doing something wrong?

Hello, I’m very new to Defold. So perhaps its something I did wrong in my code but it could be a bug (I would report it on git if there is anyone telling me its not me doing something wrong) for some reason because I can’t find something causeing my problem. It happens not only when I debug but also when I build a HTML5 . I’d like to know if I might be found a bug or its just me doing something wrong - help highly appreciated.

In one specific collection I’m playing 2 sounds time-delayed but im doing this in some collections aswell. In that specific collection sometimes both sounds and sometimes only one sound being played twice but rarely it happens that none of both being played twice.

Thats my sounds in the collection
image

Thats the message function in the GUI where everything happens. So first of all I start playing the sound “key_sound” (length 6 sec and sample rate is 44100 and 16bits) followed by time-delayed function calls each of them basically enables an element in the GUI.
image

Thats the second last function with the second sound “popup_sound”. I thought trying to stop the sound before playing the second sound helps but the first sound is not playing anymore that this moment
image

As I mentioned before I’m not quite sure why this happens specifically on this collection. Everywhere else every sound work absolutly perfect. I also checked if call that sound a second time but seachring in files showed me only one usage.
I haven´t found something similar in the forum - what i have found was a sound cracking bug from 2018 and something for android with “touch” and “click” missunderstanding.

Add a print(“foobar”) in the function where you play the sound and try again. Is it only printing once?

1 Like

Thanks for the quick answer! For some reason it seems to be called twice
image

If i search in files thats the result for this file
image

In this collection is also only 1 GUI/GUI_Script
image

thats the picture of the code - so first red dot is the function itself and the second is the function call. Nothing else that (in my oppinion) could call the function.

Any idears or anything important I forgot to mention?

Try to make this functions local. Looks like you use same names and global functions in many files

I’m sooo sry! I have just found the problem. I’m sending the message twice that activates that process but once from a completely different script. Im really sry about that :expressionless:

But thanks ALOT for the response and help!!!

5 Likes

Great you found the issue! :wink:

For future, you can also use Debugging, it’s extremely easy in Defold, add a break point and trace step by step where you go in the code :blush: it’s sometimes way quicker to find bugs in that way

5 Likes