+1 vote

I'm making a game and I want it so that when the player dies the enemy taunts the player with 1 of 12 quotes. I wanted the quotes to be random so you don't hear the same sentece said over and over. But I have zero clue to do that. I have a node called clip with 12 audiostreamplayers as its child all with the name clip with a number after it. I would love some help please

Godot version 2.3.2
in Engine by (15 points)

3 Answers

0 votes

So first off you don't need twelve audio players, you just need one. There's a doc page that explains rng. Just load all the lines into an array and pick one at random.

by (7,488 points)
+1 vote
var player = AudioStreamPlayer.new()
var audio_stream_array = [all, of, my, audio, stream, objects]
var clip_to_play = audio_stream_array[randi() % audio_stream_array.size()]

player could be accessed from scene tree using something like $AudioStreamPlayer or get_node("AudioStreamPlayer") if that's the way you're used to doing so

by (3,707 points)
0 votes

It looks to me that the line


is where you get a song. Since the loop variable, i is how you are currently getting the songs you can instead use it to index your random sequence. So, you can put it before the loop and index it to get the random values you want.

for i=1:length(audiofiles)

I removed everything else from the randomizer code you posted since I am pretty sure it is unnecessary.

Webroot.com/safe we are providing is for users to understand the process to Download, Install and Activate Webroot Products. For more information visit our website webroot.com/safe

by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.