2 registered members (Akow, tomaslolo),
1,536
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Random sounds
#309303
02/08/10 15:12
02/08/10 15:12
|
Joined: Feb 2010
Posts: 886
Random
OP
User
|
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
Expert
|
Expert
Joined: Jan 2003
Posts: 4,615
Cambridge
|
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
OP
User
|
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: Joey]
#309352
02/08/10 20:44
02/08/10 20:44
|
Joined: May 2009
Posts: 445 Peine, Germany
Razoron
Senior Member
|
Senior Member
Joined: May 2009
Posts: 445
Peine, Germany
|
Maybe:
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
Serious User
|
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]
#309361
02/08/10 21:26
02/08/10 21:26
|
Joined: Jul 2009
Posts: 150
Blackchuck
Member
|
Member
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
OP
User
|
OP
User
Joined: Feb 2010
Posts: 886
|
Blackchuck it doesn`t work. still thanks
Last edited by Random; 02/08/10 21:33.
|
|
|
|