
Originally Posted by
Dskodk
how did you load the file, then put it into an array?
im working on an mp3 player, and i want to know how to use file functions.
i want to have a file called 'songs.txt' and be able to load it into an array.
so far, i've tried:
Code:
fileLoad("songs.txt")
for(I=1,fileRead("songs.txt"):explode("|"):count()/3){
fileLocations:insertString(I,fileRead("songs.txt"):explode("|"):string((I-3)*3)) the format goes like this:
File_location|OnscreenName|Artist|
File_location|OnscreenName|Artist|
and so on.
u got any ideas?
E2 has a couple of neat little functions that use GLON. What you'll want to do is lay down an E2 file that contains an array with all the musics and their data:
Code:
Music = array()
# Music 1:
Music[1,string] = "music/path.mp3"
Music[2,string] = "Artist"
Music[3,string]= "OnScreenName"
# Music 2
Music[4,string] = "music/path2.mp3"
Music[5,string] = "Artist"
Music[6,string]= "OnScreenName"
Once you have that, you'll need to save it into a file, so you'd do something like this BELOW the music data:
Code:
String = glonEncode(Music)
fileWrite("filename.txt",String) What GLON does is encode an array into a string using some character kung-fu. It's much cleaner and powerful than doing the separation yourself, for example, you can store arrays inside OTHER arrays, you could store a whole table inside an array slot, actually.
Now, you have the file contain a string. In your music player, just load it like you normally would, and then do the following:
Code:
FileRead = fileRead("filename.txt")
Music = glonDecode(FileRead) 'Music' is now an array, containing the data you initially stored. You can also use TABLES, the only difference being when the time comes to decode it, you have to use the glonDecodeTable() function instead.
When reading songs from the array, just remember to jump 3 values each time, and read the two values after that to get your song data 
One thing about using glon is that editing your file manually becomes riskier, as doing the wrong move might break it and prevent you from loading its data properly (or at all).
BulkOS 3 -
If anyone even cares, I've made alot of huge changes to BulkOS, mainly improvements and additions on the bulkcode language. I'm not going into details now, but here's a simple game I scripted with it:

Remember, this is all done in my own language running in the E2 chip, and processed on run-time.
Bookmarks