Kontra Kommando Posted December 22, 2014 //Music Randomizer for DooM II. #library "RanDooM_Music_Player" #include "zcommon.acs" int MusicDooM[40] = {"d_e1m1","d_e1m2","d_e1m3","d_e1m4"}; //Start music script 998 ENTER {setMusic(MusicDooM[random(0,39)]);} // Randomly switch music script 999 (void) net {setMusic(MusicDooM[random(0,39)]);} ---------------------------------------------- This is a modified version of Naniyue's music Randomizer. I would like to solely have those four tracks e1m1-e1m4 play randomly. However, with the way I currently have it written, it is only playing e1m1 continuously on every level. What can I do to get it working the way I would like it to? EDIT: its seems that it does in fact work. But for some reason it plays e1m1 a lot more than the rest of them; like 5 times in a row. Any input as to why it is doing this? 0 Quote Share this post Link to post
Boon Posted December 22, 2014 Its still trying to play out of 40 songs and seems to select the first one in the array if it didn't exist. int MusicDooM[4] = {"d_e1m1","d_e1m2","d_e1m3","d_e1m4"}; script 998 ENTER {setMusic(MusicDooM[random(0,3)]);} script 999 (void) net {setMusic(MusicDooM[random(0,3)]);} 0 Quote Share this post Link to post
Gez Posted December 22, 2014 In ACS, strings are actually numbers. There is a string array somewhere, and then string variables are really integers that are used as index to the string array. This string array is made of every single string in the script, in the order in which they appear. So you have this:string array: 0: "d_e1m1" 1: "d_e1m2" 2: "d_e1m3" 3: "d_e1m4" #library "RanDooM_Music_Player" #include "zcommon.acs" int MusicDooM[40] = {0, 1, 2, 3}; //Start music script 998 ENTER {setMusic(MusicDooM[random(0,39)]);} // Randomly switch music script 999 (void) net {setMusic(MusicDooM[random(0,39)]);} Since you declare the array to 40-variable-long, but only initialize it with four values, index 4 to 39 in the MusicDoom array are set to 0. Then you get a random value from the entire array (0 to 39). 37 of these values are 0, the remaining three non-zero values being index 1, 2, and 3. Since index 0 corresponds to the first string, and the first string happens to be "d_e1m1", that's what you'll get most of the time. Now, for fun, try this: //Music Randomizer for DooM II. #library "RanDooM_Music_Player" #include "zcommon.acs" script 997 ENTER { PrintBold(s:"Hello World!"); } int MusicDooM[40] = {"d_e1m1","d_e1m2","d_e1m3","d_e1m4"}; //Start music script 998 ENTER {setMusic(MusicDooM[random(0,39)]);} // Randomly switch music script 999 (void) net {setMusic(MusicDooM[random(0,39)]);} 0 Quote Share this post Link to post
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.