Play Array of Audio Player

Hi Guys,

i currently trying to play some Audio Player one after one, but when it comes to playing those Things i get: “This invocation calls a function that has the ‘decides’ effect, which is not allowed by its context.”

I saved a bunch of Audio Player in to a Array like so:

    @editable
    var AudioClips : []audio_player_device  = array{}

and i wanna play them like this:

    playClips() : void=
        NumberofClips : int = AudioClips.Length
        var counter : int = 0

        randomClipselector()
        for(audio_player_devices : AudioClips):
            AudioClips[counter].Play()
            set counter += 1

This here is the Problem on the counter: AudioClips[counter].Play()
I tryed 0, 1, 2, 3 :smiley: but get the same Error here.
I have to select a Audio Clip by his Index right?
What do i do wrong here?

Hello, the error you are getting is because you can’t access an array index outside a failure context (i.e. AudioClips[counter] can fail if the index doesn’t exist, so you have to call it inside an if statement for example).

Anyway if you don’t need the counter variable, here’s a way easier solution :

PlayClips() : void= # Functions and variables start with capitalized letter in Verse
    for(AudioClip : AudioClips):
        AudioClip.Play()

But I just realised you said you want to play them one by one and I’m not sure to understand how you tried to make it inside your code, maybe you could tell me more ?

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.