As a developer creating games for language learning, I want to be able to specify the sound file to be played using an expression, rather than having to pre-select a specific file.
I’m not sure, but is this functionality covered in this card on the Trello roadmap?
Use case 1: Language learning game
My language game supports learning 3 languages. The user can choose which language they want to learn. When the player clicks on an image, it plays the audio for that image in the language the user is learning.
Code: Play the sound [ObjectName + LanguageChoice].wav
Result: Play the sound BeerFrench.wav (or BeerSpanish.wav, BeerEnglish.wav)
Use case 2: Multiple versions of RPG dialog
My RPG game includes dialog in four languages. The user can choose which language they want to play in. When a dialog string plays, it plays in the selected language.
Code: Play the sound [DialogString + Language].wav
Use case 3: Unique environmental sounds
My main character has different types of shields. When each shield collides with an object, it makes a specific sound.
Code: When shield collides with object, Play sound [Collision + ShieldType].wav
Benefits
Benefit 1: I only need one event in the code to play the sound. Without this function, I need a different event for each language option:
If language is English, play BeerEnglish.wav
If language is French, play BeerFrench.wav
etc.
Benefit 2: I can add a new language to the game just by adding the language-specific audio resources, and defining the [LanguageChoice] variable.
Thanks @Bouh for the explanation! It’s great to know that I can do this now using Javascript. I haven’t figured out how to do that yet, but I’ll add that to my learning path on GDevelop and will study your examples. I so appreciate the active moderation and support in this community!
Up!
Having a lot of SFX for the same action and not being able to pick them on random without making one event for each sound is annoying, and I can’t get Bouh’s solution to work properly.
You can scroll to the bottom to download the example project and extension to see if it’ll help you out.
Edit: Make sure you review the comments in the example project, there are some pretty specific steps you need to take to avoid delays, but after doing that it should let you use whatever expressions you want (so long as your filenames are named accordingly)