Randomizing voice audio files

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Vielfalt
Posts: 6
Joined: Tue Dec 10, 2024 6:07 am
Location: Austria
Contact:

Randomizing voice audio files

Post by Vielfalt »

Hi,

In my game, a character greets the player when he passes by, via bark dialogue, which works well. I'd like to randomly shuffle the voice audio files, to prevent the player from hearing the same intonation all the time. So I added this Sequence, but it always plays the first file:

Code: Select all

RandomizeNextEntry(true);
AudioWait(Voice/Receptionist - Good day sir 1);
AudioWait(Voice/Receptionist - Good day sir 2)
I probably misunderstood how RandomizeNextEntry works...?

Furthermore, I'd like there to be a minimum interval between this specific bark, so that the player isn't greeted more often than once per minute for example. What's the simplest way to implement this? Can it be done with a variable (lastBarkTime) and Lua script in Dialogue System, or do I need to write C# scripts?
User avatar
Tony Li
Posts: 22849
Joined: Thu Jul 18, 2013 1:27 pm

Re: Randomizing voice audio files

Post by Tony Li »

Hi,

If you wanted to randomly choose between 2 voice files, you could use a sequencer command like this:

Code: Select all

AudioWait(Voice/Receptionist - Good day sir [lua(RandomElement("1|2"))])
It uses the RandomElement() Lua function to randomly choose between "1" and "2".

However, if you have the added restriction of not playing a voice file if less than a minute has passed, it's probably best to write a custom sequencer command. Please see part 6 of Cutscene Sequence Tutorials.
User avatar
Vielfalt
Posts: 6
Joined: Tue Dec 10, 2024 6:07 am
Location: Austria
Contact:

Re: Randomizing voice audio files

Post by Vielfalt »

Thanks a lot, RandomElement() works like a charm here!

Regarding the minimum time interval between barks, I managed to implement it with Lua in the Dialogue System Trigger:
  • Lua condition:

    Code: Select all

    os.clock() > Variable["PrevGreetingTime"] + 60
  • Actions / Run Lua code:

    Code: Select all

    Variable["PrevGreetingTime"] = os.clock()
Coming from C++ and Swift, Lua is new to me, but I'm starting to like it :D
User avatar
Tony Li
Posts: 22849
Joined: Thu Jul 18, 2013 1:27 pm

Re: Randomizing voice audio files

Post by Tony Li »

Glad to help! Nice solution for the bark timer.
Post Reply