|
Re: Random sounds
[Re: Random]
#309365
02/08/10 21:50
02/08/10 21:50
|
Joined: Aug 2007
Posts: 1,922 Schweiz
Widi
Serious User
|
Serious User
Joined: Aug 2007
Posts: 1,922
Schweiz
|
SOUND*snd1="shdfkdh.wav";
SOUND*snd2="shdfkfsddh.wav";
SOUND*snd3="shdfksdffddh.wav";
function playrandomsound()
{
var i=integer(random(3));
switch(i)
{
case 0:
snd_play(sound1...); break;
case 1:
snd_play(sound2...); break;
case 2:
snd_play(sound3...); break;
}
}
Now you have to call the function playrandomsound if you want to hear your Sound. Edit: if "random_seed(0);" don`t work, make a update, it is the newer function from randomize.
Last edited by Widi; 02/08/10 22:00.
|
|
|
Re: Random sounds
[Re: Widi]
#309370
02/08/10 22:35
02/08/10 22:35
|
Joined: Jan 2003
Posts: 4,615 Cambridge
Joey
Expert
|
Expert
Joined: Jan 2003
Posts: 4,615
Cambridge
|
that's like: A: I need something to move heavy objects more easily. B: Here's the wheel. A: It crushes. B: You have to use it with a cart. C: I've a better solution: Here's the cube.
|
|
|
Re: Random sounds
[Re: Joey]
#309372
02/08/10 22:40
02/08/10 22:40
|
Joined: Aug 2007
Posts: 1,922 Schweiz
Widi
Serious User
|
Serious User
Joined: Aug 2007
Posts: 1,922
Schweiz
|
@Joey: Yes, your solution is the best way, i know. But with the "select" it is better to understand for a beginner i think...
@Blackchuck: If random_seed don`t work, then you don`t have the Version 7.80. As i see in other posts, i think you have a Warez Version.
Last edited by Widi; 02/08/10 22:48.
|
|
|
Re: Random sounds
[Re: Joey]
#309385
02/08/10 23:48
02/08/10 23:48
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
why not just use random sounds in an array like Joey said?
SOUND* snd_random[10]; //create pointer for 10 sounds (0-9)
//...
void play_random_sound(){
int i = random(10);
snd_play(snd_random[i], 100, 0); //sound, volume, balance
}
void main(){
snd_random[0] = snd_create("bang.wav");
snd_random[1] = snd_create("whizz.wav");
//...
snd_random[9] = snd_create("pop.wav");
make sure all sounds are in mono, wav or ogg format *untested* but 'should' work hope this helps
|
|
|
Re: Random sounds
[Re: Random]
#309427
02/09/10 10:25
02/09/10 10:25
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
void createNewSnd(STRING* sndStr, int maxNmbr) {
STRING* tempStr = str_create("");
int randNum = integer(random(maxNmbr)+1);
str_cpy(tempStr, sndStr);
str_cat(tempStr, "_");
str_cat(tempStr, str_for_int(NULL, randNum));
str_cat(tempStr, ".wav");
SOUND* tempSnd = snd_create(tempStr);
// play the sound
var sndHandle = snd_play(tempSnd, 100, 0);
// wait until finished
while (snd_playing(sndHandle)) { wait(1); }
// remove the sound
ptr_remove(sndHandle);
}
you have all your sounds named something like "attack_n.wav", where n is an number from 1 - unlimited. you call the function like:
createNewSnd("attack", 5);
And it will get you a random sound chosen from attack_1 .. attack_5. Tested and works (implemented it in my own game)! regards,
|
|
|
Re: Random sounds
[Re: Helghast]
#309430
02/09/10 10:56
02/09/10 10:56
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
you have to use integer(i) as index. I did int i = random(10); snd_play(snd_random[i], 100, 0); //sound, volume, balance
|
|
|
Re: Random sounds
[Re: Widi]
#309464
02/09/10 15:31
02/09/10 15:31
|
Joined: Feb 2010
Posts: 886
Random
OP
User
|
OP
User
Joined: Feb 2010
Posts: 886
|
Widi youre code worked the best, thanks it works now.
Thanks you all, I never say a forum that realey helps so much thanks!
|
|
|
|