• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Retrieve audio_group sounds [SOLVED]

D

DeveloBert

Guest
Hi all!

Does anybody know if there's some way in GMS2 to retrieve all the sounds included in an audio_group? Basically what I would like to achieve is a piece of code that return a relation of all the sound objects that belong to a particular audio_group.

Thanks!

- Albert -
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
A simple workaround would be to give the sounds a prefix or suffix to indicate that they belong to one or other audio group, and then loop over all sounds, retrieving those that have it in the name (string_pos\string_copy). I did at one point write a script that would read the game's own executable to get this data, but that's something that breaks as versions advance.
 
D

DeveloBert

Guest
Hi again,

In case it helps anyone, here's the final chunk of code I came up with:

Code:
var _sound_id = "my_sound_id";

for(var _snd = 0; audio_exists(_snd); _snd++)
{
    var _sound_name = audio_get_name(_snd);
    
    if(string_pos(_sound_id, _sound_name))
    {
        // Your code here
    }
}
Let's say you have the following sounds in the library: "snd_Level1_1", "snd_Level1_2", "snd_Level1_3"

You just need to set the "_sound_id" var to "Level1" and the code will detect all the library sounds which contain that string.

Cheers!
 
Top