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 → A snazzy cog that screws stuff up...
A snazzy cog that screws stuff up...
2002-03-22, 6:48 AM #1
Ok, here's my cog:

Code:
# 00_music.cog
#
# Soundtrack Code for (Edited for security reasons).
#
# TheTwistedSpasm
#
# This cog is not supported be LEC

symbols

sound track0=track0.wav local
sound track1=track1.wav local
sound track2=track2.wav local
sound track3=track3.wav local
sound track4=track4.wav local

flex cursound local
flex randfig=0 local
flex soundlen local

int music=0 local
int player local
int randnum=0 local

message startup
message activated
message timer

end


code


startup:

player = GetLocalPlayerThing();

Return;

activated:

if(!Music)
{
	Print("Music Enabled");

	music = 1;

	SetInvActivated(116, 1);

	SetTimer(1);

	Return;
}
else if(Music)
{
	Print("Music Disabled");

	music = 0;

	SetInvActivated(116, 0);

	StopSound(cursound, 3.0);

	Return;
}
Return;

timer:

Print("This proves my L33T cogging skillz!"); //Making sure the timer worked right

if(Music)

{
	randfig = Rand();

	if(randfig <= 0.2) randnum = 0;

	if(randfig <= 0.4 && randfig > 0.2) randnum = 1;

	if(randfig <= 0.6 && randfig > 0.4) randnum = 2;

	if(randfig <= 0.8 && randfig > 0.6) randnum = 3;

	if(randfig > 0.8) randnum = 4;

	cursound = PlaySoundLocal(track0[randnum], 0.4, 0, 0x0);

	Print("Track");

	PrintInt(randnum);

	soundlen = GetSoundLen(track0[randnum]);

	Sleep(soundlen);		//stop the cog till the song's done

	StopSound(cursound, 1.0);	//make sure the track stops

	SetTimer(10 + (Rand()*50));	//set a random time till next track

	Return;
}

Return;


end 


It works fine, but after the 3rd track, the sound stops. I'm almost positive that there's no bug in this code, so what in the world is the problem? Or is the code buggy and CogWriter and I are just blind? Thanks!
Cynic (sin'ik) n. One of a sect of ancient Greek philosophers who held that virtue is the ultimate goal of life, their doctrine gradually coming to symbolize insolent self-righteousness.

Drink So-Be, and play longer!
2002-03-22, 8:39 AM #2
this is strange. I see no error, but you could use randnum = Rand()*4; instead of your 5 if-lines. This has nothing to do with your problem, though...
btw: Is there no more sound played after the 3rd song or after track3?
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2002-03-22, 7:59 PM #3
3rd song. It plays 3 tracks and then the sound from this cog stops. All other sound plays fine.

Maybe I'm just dense, but how would Rand()*4 work with this?
Cynic (sin'ik) n. One of a sect of ancient Greek philosophers who held that virtue is the ultimate goal of life, their doctrine gradually coming to symbolize insolent self-righteousness.

Drink So-Be, and play longer!
2002-03-22, 11:12 PM #4
You might download the Tales of Mercenary series. I believe there was a jukebox cog of sorts just like yours.

------------------
-There are easier things in life than finding a good woman, like nailing Jello to a tree, for instance

-Tazz
-There are easier things in life than finding a good woman, like nailing Jello to a tree, for instance

Tazz
2002-03-22, 11:19 PM #5
Rand() returns a flex between 0 and 1, so Rand()*4 would be any flex between 0 and 4...
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2002-03-25, 5:07 AM #6
I see no problem with the cog that would cause that error. If it plays the first three tacks correctly, it should play the fourth.

Did your Print() statement run when the fourth track should have been played? If it did, there's a problem with your .wav or with the sound code. If it did not, then most likely the timer had not yet expired.

Only cogs defined in the level's JKL will have their symbols sections reloaded every time you load a level. So if this is an items.dat cog and you leave music at 1 when you quit the level, it will still be one in another level.

Rand()*4 returns a flex number between 0 and 4. But even though it's a flex, JK will trim the decimal portion when it is expecting an integer.

------------------
Author of the Jedi Knight DataMaster.
Visit Saber's Domain.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

↑ Up to the top!