Sequence with dynamic Wait() function

Hello, I am a bit confused about how the Sequence works. I am currently working on making a sequence of functions, which will play audio files and show some text along with it.

I want the sequence to wait until the current audio has played before it plays the next one. I then just put in the length of the audio clip in the wait function. However, this returns a wait time of 0.

Here is an example of what I am doing:

    Sequence(Func(player_voice.load_audio, 'report.wav'),
         Func(base.text.new_text, voice_strings['radio1']),
         Func(print, player_voice.audio_length),
         Func(base.text.new_text, "END"),

In the function, load_audio(), the variable audio_length is set to the actual length of the clip.

    def load_audio(self, file):
        path = 'sounds/voices/'+file = base.superloader.load_sound(path, self.emitter)
        self.audio_length =

As you can see, I print the length of the audio both in the sequence and in the function, load_audio. It returns 3 seconds from load_audio but 0 from the sequence.

Does functions called in sequences bahave differently that from regular functions? If they do, do you have any suggestions how I could solve this?

If you need me to provide more code, please let me know. Thank you for your time :slight_smile:


You read the value of player_voice.audio_length for your Wait function when you create the sequence, thus before the proper value is stored in it.

You need to make sure that you have the correct value before creating the Sequence. Otherwise it will wait for the amount of time specified at Sequence creation.

Moving the player_voice.load_audio() call just before you create your Sequence should do the trick fwiw…

1 Like

Ah okay, that makes sense. I will try to do that. Thank you for your answer, it was very helpful! :slight_smile:

1 Like

Have you looked at SoundInterval? It obviates the need to query the duration and create an explicit Wait.

I was not aware of this class. However, I will do many other things in my sequence, sounds are just one of the items, so I think it might be easier the other way. But I’ll definitely keep this in mind when I have to work with music. Thank you!

If this is because you intend to have other things run alongside the sounds, note that the Parallel class allows just that: it runs multiple intervals concurrently. It can then be itself placed in a Sequence, to be run serially with whatever other things you have in there.

For more information, see this manual page (if you haven’t already).

I am aware of Parallels, but my idea is, that the game might execute functions between voice lines in conversations. But thank you for your suggestion :slight_smile:

I see–but I’m not sure of how the use of a SoundInterval would preclude that?

Oh damn, I think i misunderstood the purpose of SoundIntervals. They are probably exactly what I could use. Thanks for making me double check :wink:

1 Like