GM:S 1.4 Any way to check if any sound from an audio group is playing?

Discussion in 'Programming' started by Bros Before Giraffes, Sep 23, 2017.

  1. Bros Before Giraffes

    Bros Before Giraffes Member

    Joined:
    Jun 24, 2016
    Posts:
    30
    For my game I have all my voice overs in an audio group called audio_vo, but I need to check if any of the sounds in the audio group are playing. I tried audio_is_playing(audio_vo), but it doesn't seem to work.
    I suppose I could put all the voice lines in an array and check them all in a loop or something, but I'm wondering if there's another way.

    Any help is appreciated!
     
  2. Dmi7ry

    Dmi7ry Member

    Joined:
    Jun 24, 2016
    Posts:
    481
    Create an array of all sounds of the group, and then check each of them with audio_is_playing.
    Something like this:
    Code:
    all_sounds = array_create_ext(snd_win, snd_lose, snd_click, snd_start);
    Code:
    /// audio_is_playing_group(array_of_sounds)
    var data = argument0;
    for (var i=0; i<array_length_1d(data); i++)
    {
        if audio_is_playing(data[i]) return true;
    }
    
    return false;
    Code:
    /// array_create_ext(value1, [value2, ...])
    
    var data = array_create(argument_count);
    
    for (var i=0; i<argument_count; i++)
    {
        data[i] = argument[i];
    }
    
    return data;
     
  3. Bros Before Giraffes

    Bros Before Giraffes Member

    Joined:
    Jun 24, 2016
    Posts:
    30
    yeah that's what I ended up doing. I was wondering if there was some simpler method that didnt involve an array and rather checking the whole group in a single function. Thanks though
     
  4. Dmi7ry

    Dmi7ry Member

    Joined:
    Jun 24, 2016
    Posts:
    481
    Ask YoYo for this feature (audio_group_get_ids or something like this), maybe it will happen (but only for GMS2, of course).
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice