Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | sir306 |
So I have a AudioStreamPlayer, that has script that iterates through a folder and pulls all the wav files and stores them in an array and then a method to play one of them at random and another to skip to the next song. When I do this in the editor it works with no issues or errors, but as soon as I export it to a runnable windows exe it fails to retrieve any of the files and shows a error of
Invalid get index ‘0’ (on base: ‘Array’).
At: res://World/MusicPlayer.gdc:32
this is the code below im using
extends AudioStreamPlayer
var music_list = []
func ready():
getallmusic()
picksong()
func input(event):
if event.isactionpressed("skipsong"):
pick_song()
func getallmusic():
var dir = Directory.new()
dir.open("res://Assets/Music/")
dir.listdirbegin()
while true:
var file = dir.get_next()
if file == "":
#no more files
break
elif not file.begins_with(".") && !file.ends_with(".import"):
music_list.append(load("res://Assets/Music/" + file))
dir.list_dir_end()
func picksong():
randomize()
var listlen = musiclist.size()
var i = randi() % (listlen - 1)
stream = musiclist[i]
print(musiclist[i])
play(0)
func onMusicPlayerfinished():
picksong()