Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (7th_zorro, Quad, VoroneTZ, 1 invisible), 623 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Random sounds #309303
02/08/10 15:12
02/08/10 15:12
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline OP
User

Joined: Feb 2010
Posts: 886
Does sombody know how to make random sounds?
I meen here is a normal sound code:


SOUND* snd_hurt = "hurt_1.wav";

function hit_obj_meat()
{
if (event_type == EVENT_SHOOT)
{
snd_play(snd_hurt,55,0);
}
}


But what if when you whant to use random sounds:


snd_play(snd_hurt1,55,0); or snd_play(snd_hurt2,55,0);


How can I do that?
I only wright in lite-c.



Re: Random sounds [Re: Random] #309306
02/08/10 15:17
02/08/10 15:17
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
Code:
SOUND** ptr = (SOUND**)malloc(sizeof(SOUND*)*3);
ptr[0] = snd_hurt1;
ptr[1] = snd_hurt2;
ptr[2] = snd_hurt3;
snd_play(ptr[integer(random(3))], 55, 0);
free(ptr);



Re: Random sounds [Re: Joey] #309314
02/08/10 16:04
02/08/10 16:04
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline OP
User

Joined: Feb 2010
Posts: 886
Thanks, but it crashes or I maby writen it wrong:

SOUND* snd_hurt = "hurt_1.wav";
SOUND** ptr = (SOUND**)malloc(sizeof(SOUND*)*3);

ptr[0] = snd_hurt1;
ptr[1] = snd_hurt2;
ptr[2] = snd_hurt3;

function hit_obj_meat()
{
if (event_type == EVENT_SHOOT)
{
snd_play(ptr[integer(random(3))], 55, 0);
free(ptr);
}
}



Last edited by Random; 02/08/10 16:08.


Re: Random sounds [Re: Random] #309321
02/08/10 16:43
02/08/10 16:43
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
well, it won't even compile that way. you first have to declare the snd_hurt1..3 sounds. and the code has to be written inside of a function. i'd advise you to first read some kind of beginners tutorial on coding.

Re: Random sounds [Re: Joey] #309352
02/08/10 20:44
02/08/10 20:44
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline
Senior Member
Razoron  Offline
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
Maybe:

Code:
SOUND*snd1="shdfkdh.wav";
SOUND*snd2="shdfkfsddh.wav";
SOUND*snd3="shdfksdffddh.wav";

function playrandomsound()
{
   random_seed(0);
   wait(1);
   var i=random(2);
   switch(i)
   {
       case 0:
       snd_play(sound1...);
       case 1:
       snd_play(sound2...);
       case 2:
       snd_play(sound3...);
   }
}



Last edited by Razoron; 02/08/10 20:45.
Re: Random sounds [Re: Razoron] #309355
02/08/10 20:51
02/08/10 20:51
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
@Razoron: That don`t will work, for the switch() you need a integer.

var i=integer(random(3));

Now i can be 0,1 or 2.

Last edited by Widi; 02/08/10 21:01.
Re: Random sounds [Re: Widi] #309358
02/08/10 21:15
02/08/10 21:15
Joined: Dec 2008
Posts: 1,660
North America
Redeemer Offline
Serious User
Redeemer  Offline
Serious User

Joined: Dec 2008
Posts: 1,660
North America
Don't you need "break" statements in that switch case? I'm not accustomed to Lite-C, but in real C you have to put break statements at the end of your cases to prevent the program from going through all of them at run time.


Eats commas for breakfast.

Play Barony: Cursed Edition!
Re: Random sounds [Re: Redeemer] #309360
02/08/10 21:19
02/08/10 21:19
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Yes.


Formerly known as JulzMighty.
I made KarBOOM!
Re: Random sounds [Re: Widi] #309361
02/08/10 21:26
02/08/10 21:26
Joined: Jul 2009
Posts: 150
B
Blackchuck Offline
Member
Blackchuck  Offline
Member
B

Joined: Jul 2009
Posts: 150
Razoro, youre code (with the var from Widi) doesen`t work becose of the function
"random_seed(0);", but without "random_seed(0);" there is no sound.
And when I wright it like this;

_______________________________________________________________
SOUND*snd1="shdfkdh.wav";
SOUND*snd2="shdfkfsddh.wav";
SOUND*snd3="shdfksdffddh.wav";

var i=integer(random(3));

function playrandomsound()
{
//deleted//
wait(1);
var i=random(2);
switch(1)//It was "switch(i)"
{
case 0:
snd_play(sound1...);
case 1:
snd_play(sound2...);
case 2:
snd_play(sound3...);
}
}
______________________________________________________________
There should be no warnings.

Last edited by Blackchuck; 02/08/10 21:35.

I have know Gamestudio/A7 Commercial Edition 7.84
Re: Random sounds [Re: Blackchuck] #309362
02/08/10 21:32
02/08/10 21:32
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline OP
User

Joined: Feb 2010
Posts: 886
Blackchuck it doesn`t work.
still thanks

Last edited by Random; 02/08/10 21:33.


Page 1 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