|
68 registered (alibaba, Blink, BlueFlame, aztec, 3dgs_snake, Bone, bodden, Benni003, Alan, BigFaischty, 7 invisible),
150
Guests and
20
Spiders online. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
#309365 - 02/08/10 22:50
Re: Random sounds
[Re: Random]
|
Serious User
Registered: 08/29/07
Posts: 1457
Loc: Schweiz / Brasil
|
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.
Edited by Widi (02/08/10 23:00)
|
|
Top
|
|
|
|
#309370 - 02/08/10 23:35
Re: Random sounds
[Re: Widi]
|
Expert
Registered: 01/01/03
Posts: 4201
Loc: Heidelberg
|
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. 
|
|
Top
|
|
|
|
#309385 - 02/09/10 00:48
Re: Random sounds
[Re: Joey]
|
User
Registered: 07/30/08
Posts: 655
|
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
|
|
Top
|
|
|
|
#309427 - 02/09/10 11:25
Re: Random sounds
[Re: Random]
|
Expert
Registered: 01/02/04
Posts: 2863
Loc: 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,
|
|
Top
|
|
|
|
#309430 - 02/09/10 11:56
Re: Random sounds
[Re: Helghast]
|
User
Registered: 07/30/08
Posts: 655
|
you have to use integer(i) as index. I did  int i = random(10); snd_play(snd_random[i], 100, 0); //sound, volume, balance
|
|
Top
|
|
|
|
#309464 - 02/09/10 16:31
Re: Random sounds
[Re: Widi]
|
Junior Member
Registered: 02/08/10
Posts: 84
|
Widi youre code worked the best, thanks it works now.
Thanks you all, I never say a forum that realey helps so much thanks!
_________________________
Im working on one game; Siriusly: Shooter game / 3DGS (Realistig) And totaly intrested in game physics!
I have Gamestudio/A8 Commercial
|
|
Top
|
|
|
|
|