Re: Help with my take on Memory Train

The variable tone is actually an array of sounds and the left and right brackets after sound mean an array of sounds. THe [ a-t ]  sign is what tells you that you are looking at a handle. So sound[] (note the punctuation) is not, as you seem to think, an array of sound handles. This is actually really important because if you remember, a handle must point back to an object. In short, a handle is just a way to make things easier for you, because if you are developing a game, you don't ever have to use handles, but using them makes your task tremendously easier and your code cleaner.
Following from the handles vs arrays thing, you talk about music as being a handle. You seem to be sort of confused as to what a handle is and what an array is. The tones are an array of sounds, and nothing else, so handles have nothing to do with it right now. The way the tutorial shows you how to load sounds gets really cumbersome if you are loading more than about 4 sounds, because you have to load each file separately. For arrays with more items, you will want to do something similar to what the language tutorial shows you, and use a loop to automatically increment your array index to load more files automatically.
Here's a sample code fragment that I haven't tested. That usually means you'll see some minor compile errors, but the gist of how you ought to work it is there. I'll try and explain things with comments to help you.

sound[] music(30);//declare an array of sounds called music and give it a size of 30.
void main()
{
show_game_window("stuff"); //allows keyboard input
//use a loop to expedite loading of sequentially numbered files
for(uint x=1; x==music.length(); x++) //what will happen now is that the variable x, which we declared in the for statement, will have 1 added to it each time the loop runs. It will stop when x = the length of the music array, which we defined to be 30.
{
music[x-1].load("sounds/music/"+x+".wav"); //array index always starts at 0 and goes to length()-1. Since x starts at 1 and goes to music.length(), you have to do a minus 1 in order to keep the array index and the variable of x synchronized. Notice also how I used string concatonation in the call to sound.load, in order to quickly load the files with that number. I assume that the file extension is wav, for the sake of simplicity.
}
//play a random music sound and wait for 5 seconds so that you can hear part of it.
music[random(0,music.length()-1].play(); //look carefully at the arguments I give to the random function. Remember that the minimum index of any array is 0 and the maximum index is the array's length minus 1. So the generator will now return a number between 0 and 29, and the sound associated with that file will play, if it loaded correctly.
wait(5000);//wait for 5 s.
}

_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Orin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : keyIsFull via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Orin via Audiogames-reflector

Reply via email to