Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → sounds problem
sounds problem
2004-12-02, 10:02 AM #1
Maybe old question... ?

Ok.
I have cog which playing several wav's in random order
one after another.
But after about 1 sec. each sound stop playing :/
(sound has lenght from 2 to 7 sec. )

So i set
Sleep(GetSoundLen(sound));

But this doesn't help. Still sound is stoppinag after about 1 sec .

How to fix that ?
please HELP


greetz
Ortheza
-= Jedi Knight I forever =-
2004-12-02, 1:04 PM #2
Let us see the COG! Maybe we can see the problem...
Edward's Cognative Hazards
2004-12-03, 1:06 PM #3
ok, here it is:
------------------------------------------------------------
Code:
# Jedi Knight Cog Script
#
# THUNDERS
#

# flags=0x240

symbols

thing 		player		local
sector		player_sector	local

thing		pieron_emiter
thing		tmp_thing local

vector		s_pos	local
vector		s_look  local
vector		s_pos_a	local
vector		s_look_a  local

template	s_tpl	
flex		min_time=1
flex		random_mult=2

sound		thunder0
sound		thunder1
sound		thunder2
sound		thund	local

surface		surf_exit0a	linkid=300
surface		surf_exit0b	linkid=300

message		startup
message		pulse	
message 	crossed

int 		id 		local
flex		duration	local
int		inside		local

end				
# ========================================================================================

code
startup:
	
	player = GetLocalPlayerThing();
	s_pos  = GetThingPos(pieron_emiter);
	s_look = GetThingLVec(pieron_emiter);
	SetPulse(min_time);
	inside = 0;
	
return;
#---------------------------------
crossed:

	if(GetSenderID()==300)
	{
		if(inside==0) { inside=1; }
		else
		if(inside==1) { inside=0; }
	}

return;
#---------------------------------
pulse:
	
	if(rand()>0.5)
	{
		
		player_sector =GetThingSector(player);

		s_pos_a = VectorAdd(s_pos, VectorSet((Rand()-0.5)*20, (Rand()-0.5)*20, (Rand()-0.5)*0 ) );	
		s_look_a = VectorSet( 90+(Rand()-0.5)*30, (Rand()-0.5)*180, (Rand()-0.5)*180 ); // P Y R

		tmp_thing=CreateThingAtPosNr( s_tpl,player_sector,s_pos_a, s_look_a);
		
		thund=thunder0[(rand()*6)%3];
		duration=getSoundLen(thund);		
			
		
		if(!inside) PlaySoundLocal( thund, rand()+0.5,0,0x101a4);
		
		Sleep(duration);
		SetPulse(duration+rand()*random_mult);
	}

Return;

end

[Code tags, please]
-------------------------------------------------------------------------
-= Jedi Knight I forever =-
2004-12-03, 2:26 PM #4
min_time i think should be > 1 (and maxtime increased respectively)
This is retarded, and I mean drooling at the mouth
2004-12-03, 2:31 PM #5
My suggestions are remove the Sleep(duration); and change the sound flags from 0x101a4 to 0x10184.

The problem with the sound stopping after a second is due to the flag 0x20, so changing 0x101a4 to 0x10184 should let the sounds play their full duration.

QM
2004-12-03, 2:43 PM #6
OK... I seem to have found some reasons to why you only hear for one second.
1. The sound flags. Flag 0x20 that minimizes the volume after a second, and Flag 0x10000 that won't allow any new sound to be played by the same thing
2. The if(rand()>0.5) will also do so that the sound won't play for some time.

And something I find unecesary. Sleep(duration); It ain't needed.

Hope this helps.

/Edward
Edward's Cognative Hazards
2004-12-03, 2:57 PM #7
Actually, that's not necessary.
And I'm going to do some stuff to try and make this a bit cleaner.

Code:
# Jedi Knight Cog Script
#
# THUNDERS
#
# flags=0x240

symbols
flex     min_time=1
flex     random_mult=2

thing    player        local
sector   player_sector local

thing    pieron_emiter

vector   s_pos         local
vector   s_look        local
vector   s_pos_a       local
vector   s_look_a      local

template s_tpl

sound    thunder0
sound    thunder1
sound    thunder2
sound    thund         local

surface  surf_exit0a   linkid=300
surface  surf_exit0b   linkid=300

message  startup
message  pulse
message  crossed

int      id            local
int      inside = 0    local
flex     duration      local
end
#==============================================================================

code

startup:
player = GetLocalPlayerThing();
s_pos = GetThingPos(pieron_emiter);
s_look = GetThingLVec(pieron_emiter);
SetPulse(min_time);

return;
#---------------------------------
crossed:
if(GetSenderID()==300)
   inside = 1 - inside;

return;
#---------------------------------
pulse:
if(rand()>0.5)
{
   player_sector = GetThingSector(player);

   s_pos_a = VectorAdd(s_pos, VectorSet((Rand()-0.5)*20, (Rand()-0.5)*20, (Rand()-0.5)*0 ));
   s_look_a = VectorSet(90+(Rand()-0.5)*30, (Rand()-0.5)*180, (Rand()-0.5)*180); // P Y R

   CreateThingAtPosNr(s_tpl,player_sector,s_pos_a, s_look_a);

   thund=thunder0[(rand()*6)%3];
   duration=getSoundLen(thund);

   if(!inside)
      PlaySoundLocal(thund, rand()+0.5,0,0x10184);
   SetPulse(duration + (rand()*random_mult));
}
Return;
end


Not much has happened in way of code changes. Killed the sleep. That was the main source of the problem I think. You'd sleep, and by the time the sleep was over, the pulse would have run again. I also cleaned up the crossed code. I also initialized inside in the symbols section instead of startup. There's no reason to initialize in the code section when it can be done in the symbols (Some things can't be done this way, ie, when they require cog verbs)

As for some suggestable code ettiquette:
if(inside==0) { inside=1; }
Don't do that. If it's a single line, you don't need brackets. Secondly, putting it on the same line makes it sloppy looking. Brackets are intended for blocks of code.

else
if(inside==1) { inside=0; }

Here... there's no reason for the second if. If insides not 0, it'll be 1. There's no other possibilities. That's what the else is for. Again brackets not necessary.

A nicer (neater) way to write that would've been:
Code:
if(inside == 0)
   inside = 1;
else
   inside = 0;


Note: I'm not saying this has to be done, just makes things more readable in general. There are many styles, but those usually differ in indentation and the places of brackets when using blocks of code.

inside = 1 - inside;
does all of that for you. If it's currently 1, it becomes 0. If it's 0, it becomes 1.
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come
2004-12-03, 2:58 PM #8
Hmm, guess I shoulda refreshed the damn page. Some solutions already posted.
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come
2004-12-03, 4:00 PM #9
Sorry guys for this ugly cog :-) but some parts of this cog has been erased to clarify a little, but some unnecesssry brackets remains.

Changing sound flags fixed my problem.

THANX alot :]

Now i can make next part of Kamino map.
-= Jedi Knight I forever =-

↑ Up to the top!