When I open it, it won’t change the audio.
Excuse me if I am completely wrong here, I have never loaded streams like this, but should you not be loading possibleSongs[nextSong] ?
Again, if I am totally off the mark here, apologies in advance.
It might help you to use static typing, and paste your scripts instead of using a screenshot.
There’s a lot of little things going wrong, the largest being using load
on a float.
# should be randi_range v v should start at 0
var nextSong := random.randf_range(1, possibleSongs.size())
# nextSong is float, not a path, load should fail and give an error
self.stream = load(nextSong)
Since there is little reason to keep the nextSong
variable you could use pick_random()
on your array to load a random path.
self.stream = load(possibleSongs.pick_random())
Alternatively, you might be better off using an AudioStreamRandomizer as your “stream”. Then you can pop in your audio files and let it handle the randomization for you.
Edit: but the posters above, pauldrewett and gertkeno, are correct about the issues they found
I actually fixed it by putting this code:
possiblesSongs.shuffle
self.stream = load(possibleSongs[1])
Make sure you are calling shuffle
(or use pick_random()
) or else it won’t be random and instead play the second song every time.
possiblesSongs.shuffle() # needed parenthesis
self.stream = load(possibleSongs[0]) # the first song is 0
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.