Links
AUM Magazine
Newest Posts
cloud plugin, made by ello five years ago
by Error014
1 second ago
Crytek's SSAO development thread
by jane
51 seconds ago
How to turn the my entity smoothly to a target?
by Spirit
15 minutes 44 seconds ago
Wierd invalid pointer.
by paracharlie
Today at 14:23
String comparison
by 3dgs_snake
Today at 14:02
Latest Screens
Overlay Window Project
Marble Ball Dash
Sea
Gravix
Secret Of The Sword - Castle Rooms
Who's Online
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
Newest Members
Dr_Varsims, Doford, Sunshine21, tgamorris76, Polygon
14951 Registered Users
Page 2 of 3 < 1 2 3 >
Topic Options
Rate This Topic
#309365 - 02/08/10 22:50 Re: Random sounds [Re: Random]
Widi Offline
Serious User

Registered: 08/29/07
Posts: 1457
Loc: Schweiz / Brasil
Code:
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]
Joey Offline
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.

wink
_________________________
www.phosphor-games.de.tc

Top
#309372 - 02/08/10 23:40 Re: Random sounds [Re: Joey]
Widi Offline
Serious User

Registered: 08/29/07
Posts: 1457
Loc: Schweiz / Brasil
@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.


Edited by Widi (02/08/10 23:48)

Top
#309374 - 02/08/10 23:44 Re: Random sounds [Re: Widi]
Joey Offline
Expert

Registered: 01/01/03
Posts: 4201
Loc: Heidelberg
i was not complaining about it ^^ - it's really nice of you to help people out.
_________________________
www.phosphor-games.de.tc

Top
#309385 - 02/09/10 00:48 Re: Random sounds [Re: Joey]
MrGuest Online
User

Registered: 07/30/08
Posts: 655
why not just use random sounds in an array like Joey said?

Code:
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
#309425 - 02/09/10 11:17 Re: Random sounds [Re: MrGuest]
Joey Offline
Expert

Registered: 01/01/03
Posts: 4201
Loc: Heidelberg
you have to use integer(i) as index.
_________________________
www.phosphor-games.de.tc

Top
#309427 - 02/09/10 11:25 Re: Random sounds [Re: Random]
Helghast Online
Expert

Registered: 01/02/04
Posts: 2863
Loc: The Netherlands
Code:
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:

Code:
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,
_________________________
Formerly known as dennis_fantasy
http://www.designorhea.com/

Top
#309430 - 02/09/10 11:56 Re: Random sounds [Re: Helghast]
MrGuest Online
User

Registered: 07/30/08
Posts: 655
Originally Posted By: Joey
you have to use integer(i) as index.
I did laugh
Originally Posted By: MrGuest
int i = random(10);
snd_play(snd_random[i], 100, 0); //sound, volume, balance

Top
#309431 - 02/09/10 11:58 Re: Random sounds [Re: MrGuest]
Joey Offline
Expert

Registered: 01/01/03
Posts: 4201
Loc: Heidelberg
ah damn implicit type conversion wink. with a good compiler you'd at least get a warning here ^^.
_________________________
www.phosphor-games.de.tc

Top
#309464 - 02/09/10 16:31 Re: Random sounds [Re: Widi]
Random Online
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
Page 2 of 3 < 1 2 3 >


Moderator:  HeelX, Lukas, Shadow969, Tobias, TWO, VeT 

lite-c | chip programmers | download | shop | resources | magazine | manual | support faq | wiki | bugs | beta features | forecast

Conitec Datasystems, Inc · 5000 Thorne Drive, Suite F · La Mesa, CA 91941 · Tel +1 (619) 462-0515 · Fax +1 (619) 462-0519 · info (at) 3dgamestudio.net