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 → can two progresses run in one moment - cog problem.
can two progresses run in one moment - cog problem.
2003-06-28, 1:44 AM #1
Code:
# Jedi Knight Cog Script
#
# [EH_AceTFL]

symbols

message		crossed

thing           cc1
thing           cc2

surface		adjoin	


sound           tieenginewhine

int 		done=0				local

end

code
#------------------------------------------------------------------------
crossed:
	if (done) return;
        playsoundthing(tieenginewhine, cc1, 1.0, -1, 175, 129);
        playsoundthing(tieenginewhine, cc2, 1.0, -1, 175, 129);
	call movecc1;
	call movecc2;
return;

movecc1:
        movetoframe(cc1, 1, 5);
	waitforstop(cc1);
        movetoframe(cc1, 2, 10);
	waitforstop(cc1);
        movetoframe(cc1, 3, 10);
	waitforstop(cc1);
        movetoframe(cc1, 4, 10);
	waitforstop(cc1);
        movetoframe(cc1, 5, 10);
	waitforstop(cc1);
	destroything(cc1);
return;

movecc2:
	movetoframe(cc2, 1, 5);
	waitforstop(cc2); 
	movetoframe(cc2, 2, 10);
	waitforstop(cc2); 
	movetoframe(cc2, 3, 10);
	waitforstop(cc2); 
	movetoframe(cc2, 4, 10);
	waitforstop(cc2); 
	movetoframe(cc2, 5, 20);
	waitforstop(cc2); 
        destroything(cc2);
return;
end


ok: cog works in fact, but now as i want : when it start first CC move and second (or first hmm) move to first frame and stop. second car move to 4 frame, and all delate.

Wrong is that one car is standing, and second car wont fly to 5 frame.

HELP NEED [http://forums.massassi.net/html/smile.gif]

------------------
The miners of Kiith Somtaaw sacificed much, and risked all. For their efforts they were brought into the inner most circle of Hiigaren power. Naabal, S'jet, and Sobanii bowed before them. And from that day to this, Somtaaw's children have been known to one and all as Beastslayers..
2003-06-28, 4:13 AM #2
Both cars move at the same time, right?

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-06-28, 5:16 AM #3
You might want to check your frame setup and make sure the thing's starting position is the same as frame 0.

------------------
"The Just shall live by faith." - Galatians 3:11
To edit is human... To COG is divine!!

pegasus_1984: Stop bushing that dang suck button.
guitarofgold: NOOOOOOOOO!!!!
-------[end post]-------
Catloaf, meet mouseloaf.
My music
2003-06-28, 9:57 AM #4
well, frames are ok, cars should move at same time.

------------------
The miners of Kiith Somtaaw sacificed much, and risked all. For their efforts they were brought into the inner most circle of Hiigaren power. Naabal, S'jet, and Sobanii bowed before them. And from that day to this, Somtaaw's children have been known to one and all as Beastslayers..
2003-06-28, 7:46 PM #5
The way you have it, it's not going to work. JK will wait for the first call to end before making the second call. You should recode that with timers.

Quote:
<font face="Verdana, Arial" size="2">can two progresses run in one moment</font>


Not really - depends what you mean. Yes, two events in a cog can run at the same time. But if you use Sleep() or WaitForStop() to pause your code, JK will wait before continuing execution where it left off. If you use a timer, JK will set the timer and go on to the next line of code.

Picture your code written like this:
Code:
crossed:
if (done) return;
playsoundthing(tieenginewhine, cc1, 1.0, -1, 175, 129);
playsoundthing(tieenginewhine, cc2, 1.0, -1, 175, 129);
// JK performs call to movecc1:
movetoframe(cc1, 1, 5);
....
destroything(cc1);
//JK performs call to movecc2:
movetoframe(cc2, 1, 5);
....
destroything(cc2);
//return from crossed...
return;


------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-06-28, 8:01 PM #6
Another thing to remember about Sleep() and verbs like it, is that when JK is given an execution starting-point in a cog, it creates what I'll call a thread.

Each cog may have four threads running at once. When you use Sleep(), the thread is paused. This means, that you don't get more threads. Suppose you have five event messages that could be called at nearly the same time - if they all use a sleep, one of those messages will not be called if the events occur within the shortest sleep's pause time.

And there's nothing to stop a thread from rerunning code in a message - while that message is still sleeping. Consider this peice of code:
Code:
activated:
   if(on) Return;
   on=1;
   PlaySoundLocal(wav, 1, 0, 0);
   Sleep(GetSoundLen(wav));
   on=0;
Return;


This message is prepared to be called more than once, but it will only let one thread at a time play the sound.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-06-28, 11:06 PM #7
Then.. how should this cog look like?

------------------
The miners of Kiith Somtaaw sacificed much, and risked all. For their efforts they were brought into the inner most circle of Hiigaren power. Naabal, S'jet, and Sobanii bowed before them. And from that day to this, Somtaaw's children have been known to one and all as Beastslayers..
2003-06-30, 10:20 AM #8
A lot like this:
Code:
# Jedi Knight Cog Script
#
# [EH_AceTFL]
#==============================================================#
symbols

message   crossed
message   timer

thing     cc1
thing     cc2

surface   adjoin

sound     tieEngineWhine

int       done=0           local
int       id               local
int       channel1         local
int       channel2         local

end
#==============================================================#
code
#------------------------------------------------------
crossed:
	if(done) Return;
	done = 1;
	channel1 = PlaySoundThing(tieEngineWhine, cc1, 1, 20, 175, 0x81);
	channel2 = PlaySoundThing(tieEngineWhine, cc2, 1, 20, 175, 0x81);
	SetTimerEx(0, 1, 0, 0);
	SetTimerEx(0, 2, 0, 0);

Return;
#------------------------------------------------------
timer:
	id = GetSenderID();
	if(id == 1)
	{
		MoveToFrame(cc1, 1, 5);
		WaitForStop(cc1);
		MoveToFrame(cc1, 2, 10);
		WaitForStop(cc1);
		MoveToFrame(cc1, 3, 10);
		WaitForStop(cc1);
		MoveToFrame(cc1, 4, 10);
		WaitForStop(cc1);
		MoveToFrame(cc1, 5, 10);
		StopSound(channel1, 5);
		WaitForStop(cc1);
		DestroyThing(cc1);
	}
	else if(id == 2)
	{
		MoveToFrame(cc2, 1, 5);
		WaitForStop(cc2);
		MoveToFrame(cc2, 2, 10);
		WaitForStop(cc2);
		MoveToFrame(cc2, 3, 10);
		WaitForStop(cc2);
		MoveToFrame(cc2, 4, 10);
		WaitForStop(cc2);
		MoveToFrame(cc2, 5, 20);
		StopSound(channel2, 5);
		WaitForStop(cc2);
		DestroyThing(cc2);
	}

Return;
#------------------------------------------------------
end


There's not much of a visible difference, but SetTimerEx() is used to create new threads. Also, done is now set to 1 so crossed will die after it checks for done, the thing sounds are now given channel variables so they can be stopped and faded out, the sounds are given a min distance of a little less than 2 JKUs (-1 just uses a default of 1/2 a JKU), and the sound flags are now given in hex (makes no difference, but you should always do this for readability).

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

↑ Up to the top!