Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (7th_zorro, degenerate_762, AndrewAMD, ozgur), 774 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: Random sounds [Re: Random] #309365
02/08/10 21:50
02/08/10 21:50
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
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.

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 Offline
Expert
Joey  Offline
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.

wink

Re: Random sounds [Re: Joey] #309372
02/08/10 22:40
02/08/10 22:40
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
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: Widi] #309374
02/08/10 22:44
02/08/10 22:44
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
i was not complaining about it ^^ - it's really nice of you to help people out.

Re: Random sounds [Re: Joey] #309385
02/08/10 23:48
02/08/10 23:48
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
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

Re: Random sounds [Re: MrGuest] #309425
02/09/10 10:17
02/09/10 10:17
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
you have to use integer(i) as index.

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 Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
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
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Random sounds [Re: Helghast] #309430
02/09/10 10:56
02/09/10 10:56
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
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


Re: Random sounds [Re: MrGuest] #309431
02/09/10 10:58
02/09/10 10:58
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
ah damn implicit type conversion wink. with a good compiler you'd at least get a warning here ^^.

Re: Random sounds [Re: Widi] #309464
02/09/10 15:31
02/09/10 15:31
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline 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!



Page 2 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1