[Solved] Play sound based on variable

I am planning a tutorial system with speech.
And would love to select which sound to play based on a variable.
I have the names of the soundfiles to play in an array.
But the “play sound” action cannot use a variable, only a selected soundfile.


So is the only solution to add a condition for each and every soundfile?

Hello @chucklebeast!

I suppose there are many possibilities to do what you want.
First, you can use events to trigger a certain soundfile when condition is reached.
Second, if you are fluent with Javascript, you can use it to do the job.
In last, depending of the number of the soundfiles, you can employ variables which can be used to start the listening of soundfiles.

If you expose more precisions on your project, we will can certainly bring more infos.

A+
Xierra

1 Like

There is an extension I built a while back called Sound ls and Music by Filename. You’ll need to ensure your sounds are loaded into the scene, but it should allow you to pass your filenames from your array.

Its in the community extension list in the engine.

3 Likes

Will try that extension - (to others looking for this: you will have to switch to “include experimental” when searching for the extension inside Gdevelop)

(Solved) The extension seems to work perfectly! thnx @Silver-Streak
Again I cant change the top subject to include (Solved) hmmmm

Glad it helped. I’ll close out the thread.

2 Likes