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 → Cog not recieving activated message
Cog not recieving activated message
2002-08-17, 9:16 AM #1
I'm working on a cog to launch a squadron of fighters from a hanger. The fighters must move to a "ready" position, a "launch" position, and then takes off. When the first fighter reaches the launch position the second fighter begins to move to the ready position, etc.
When the switch is activated, the the cog sends a message to the baydoor cog which returns if the doors are opened or closed.
The variable "shipsready" is the number of ships already in the ready position.
My problem is that the cog is not recieving the "activated" message from the switch.

Code:
# Jedi Knight Cog Script
#
# fd_ship.COG
#
# Launches a squadron of fighters
#
#
# This Cog is Not supported by LucasArts Entertainment Co
#==============================================================#

symbols

thing        ship0                              linkid=0                      
thing        ship1                              linkid=0                      
thing        ship2                              linkid=0                      
thing        ship3                              linkid=0                      
thing        ship4                              linkid=0                      
thing        ship5                              linkid=0                      
thing        ship6                              linkid=0                      
thing        ship7                              linkid=0                      
thing        ship8                              linkid=0                      
thing        ship9                              linkid=0                      
thing        tempship                           local                         

surface      switch                             linkid=1                      

int          closedstring                                                     
int          launchstring                                                     
int          shipsready                                                       
int          readyframe                                                       
int          launchframe                                                      
int          numframes                                                        
int          numships                           local                         
int          launching=0                        local                         
int          curship                            local                         
int          inreadypos                         local                         
int          endframe                           local                         
int          closed                             local                         
int          dummy                              local                         
                    
sound        activated=set_hi2.wav              local                         
sound        blocked=lgclick1.wav               local                         
sound        doorclosed=00alarmloop01.wav       local                         

flex         readydeley=0.25                    local                         
flex         launchdeley=0.5                    local                         
flex         readyspeed=2                       local                         
flex         launchspeed=4                      local                         
flex         movespeed=8                        local                         
flex         soundlen                           local                         

cog          baydoor                                                          

message      startup                                                          
message      activated                                                        
message      arrived                                                          
message      timer                                                            

end                                                                           
#==============================================================#
code
#------------------------------------------------------
startup:
	Sleep(1);
	for(curship = 0; ship0[curship] >= 0 && curship < 10; curship = curship + 1)
	{
		numships = numships + 1;
	}
	endframe = numframes - 1;
Return;
#------------------------------------------------------
activated:
	if(GetSenderID() == 0) Return;
	if(launching)
	{
		PlaySoundLocal(blocked, 1.0, 0, 0);
		Return;
	}
	launching = 1;

	SetWallCel(switch, 1);
	PlaySoundLocal(activated, 1.0, 0, 0);
	closed = SendMessageEx(baydoor, user0, 1, -1, -1, -1);	// Check baydoor status
	if(closed)				// if doors are closed
	{
		soundlen = GetSoundLen(doorclosed);
		soundlen = soundlen * 3;
		dummy = PlaySoundLocal(doorclosed, 1.0, 0, 0x5);
		jkPrintUNIString(-1, closedstring);
		SetTimerEx(soundlen, 3, -1, -1);
		SetWallCel(switch, 1);
		launching = 0;
		Return;
	}
	curship = 0;
	inreadypos = shipsready;
	jkPrintUNIString(-1, launchstring);
	call launch;

Return;
#------------------------------------------------------
arrived:
	tempship = GetSenderRef();
	if(GetCurFrame(tempship) == readyframe)
	{
		SetTimerEx(readydeley, 1, tempship, -1);
	}
	else if(GetCurFrame(tempship) == launchframe)
	{
		SetTimerEx(launchdeley, 2, tempship, -1);
		call launch;
	}
	else if(GetCurFrame(tempship) == endframe)
	{
		DestroyThing(tempship);
	}

Return;
#------------------------------------------------------
timer:
	tempship = GetParam(0);
	if(GetSenderId() == 1)
	{
		call launch;
	}
	else if(GetSenderId() == 2)
	{
		MoveToFrame(tempship, endframe, movespeed);
	}
	else if(GetSenderId() == 3)
	{
		StopSound(dummy, 1);
	}
Return;
#------------------------------------------------------
launch:
	if(curship == numships)
	{
		SetWallCel(switch, 0);
		SendMessageEx(baydoor, user0, 0, -1, -1, -1);
		Return;
	}
	else if(curship == inreadypos)
	{
		MoveToFrame(ship0[curship], readyframe, readyspeed);
		inreadypos = inreadypos + 1;
	}
	else if(curship < numships)
	{
		MoveToFrame(ship0[curship], launchframe, launchspeed);
		curship = curship + 1;
	}

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


[This message has been edited by force_dude (edited August 17, 2002).]
2002-08-18, 1:19 AM #2
Activated is defined twice, as a sound and as a message. That's probably the problem.
APT 1, 2, 3/4, 5/6
TDT
DMDMD

http://veddertheshredder.com
2002-08-18, 4:18 AM #3
[yoda voice]Hmmmm... A very disorganized cog I see. You have to move from top to bottem to top, yessss.[/yoda voice] I got a little confused on the cog, I can't quite understand it. Get Parsec from SaberMaster's sig, and chack it with that. Me, GBK, and SaberMaster ( [http://forums.massassi.net/html/rolleyes.gif] ) use it all the time to check our syntax. Other then that... Here's something to help/solve your problems.
Code:
Startup:
   Sleep(1);
   For(curship=0; curship<10; curship=curship+1)
   {
      If(ship0[curship] >= 0) numships = numships +1;
   }
   endframe = numframes - 1;
Return;

In Activated use If(GetSenderID() != 1) Return; insted of == 0, safer that way.
Second SetWallCal(switch, 1); should be SetWallCel(switch, 0); You want it to turn back off, not keep on. [http://forums.massassi.net/html/wink.gif] Now try it. [http://forums.massassi.net/html/smile.gif]

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

The Magician Saber System.

[This message has been edited by Descent_pilot (edited August 18, 2002).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2002-08-18, 12:08 PM #4
Yeah, activated isn't being called because it's defined twice. Only the first variable with that name is recognized. Parsec will catch that error, but as it is, it will allow you to use message names in cogs though they are reserved words.

I don't think that code is badly written at all. Perhaps a little redundant, but that's not bad. You don't need a sleep on startup there because you're only working with values passed from the JKL. I would use:
Code:
for(numships=0; ship0[numships] >= 0 && numships < 10; numships=numships+1);

As the for loop in the startup message. Parsec will give you a warning for the semicolon (as it's a common mistake), but the code is fine.

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

[This message has been edited by SaberMaster (edited August 18, 2002).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-08-18, 12:48 PM #5
SaberMaster, the way you have the For loop is a syntax error, no semis after the (), same as a If/Else statement. I'm not sure if you need () around the middle parameter. If it will get called right w/o them.

I perfer cogs that are organized as much as they can in chronological order, but that's me. *shugs*

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

The Magician Saber System.

[This message has been edited by Descent_pilot (edited August 18, 2002).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2002-08-19, 2:16 PM #6
Quote:
<font face="Verdana, Arial" size="2">SaberMaster, the way you have the For loop is a syntax error, no semis after the (), same as a If/ Else statement. I'm not sure if you need () around the middle parameter. If it will get called right w/o them.</font>


As I explained, having a semicolon at the end of a for loop is a common mistake, but it is not an error. Yes, it is the same as the if statament, and no it is not a syntax error.

As for parentheses, they are used for two purposes: to enclose parameters, and to raise the precedence of part of an expression. For example:
Code:
if((boolean))

The outer set encloses the if statement's parameters. The inner set (which is useless) would be used to raise the precedence of the expression inside it - meaning that it would be evaluated before the rest of the expression. Now look at this example:
Code:
for(i=1; i < 10; i=i+1);

Note that the outer set (in bold) of parentheses is still there to enclose the parameters of the for statement. There's no need to enclose the condition with parentheses.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-08-19, 5:55 PM #7
Hmmm... never knew/saw that. Sorry. [http://forums.massassi.net/html/redface.gif] As for the () I know all about them (except how to spell it correctly [http://forums.massassi.net/html/tongue.gif] ), and what they do. I was talking about the middle parameter in the For loop for force_dude. (There's a tongue twister [http://forums.massassi.net/html/tongue.gif] )

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

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2002-08-20, 6:10 AM #8
Thanks, that fixed it.

↑ Up to the top!