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 → SendMessageEx
SendMessageEx
2003-02-03, 9:17 AM #1
Hey, I'm trying to use the SendMessageEx function in one of my cogs. It's sending ok, but when it gets to the second cog, it's saying the variable (i called it deadnum) is equal to 0. How do i get the second cog to recognize the variable?
2003-02-03, 9:36 AM #2
If it helps, here's the two codes:

The cog that sends the message:
Code:
# Jedi Knight Cog Script
#
# PSOGENERATOR.COG
#
# Generates enemies in waves like in Phantasy Star Online
# 
# Created by Jon Newmuis
# 

symbols

sector		startrig	linkid=0

// Wave One

thing		ghostoone	linkid=2
thing		ghostotwo	linkid=2
thing		ghostothree	linkid=2
thing		ghostofour	linkid=2
thing		ghostofive	linkid=2

template	oone
template	otwo
template	othree
template	ofour
template	ofive

flex		enemiesin1=5

// Wave Two

thing		ghosttone	linkid=2
thing		ghostttwo	linkid=2
thing		ghosttthree	linkid=2
thing		ghosttfour	linkid=2
thing		ghosttfive	linkid=2

template	tone
template	ttwo
template	tthree
template	tfour
template	tfive

flex		enemiesby2=10

// Wave Three

thing		ghosttho	linkid=2
thing		ghosttht	linkid=2
thing		ghostthth	linkid=2
thing		ghostthfo	linkid=2
thing		ghostthfi	linkid=2

template	tho
template	tht
template	thth
template	thfo
template	thfi

flex		enemiesby3=15

// Sounds

sound		gensound0=forcesee01.wav	local
sound		gensound1=forcethrow01.wav	local
sound		stopsound=funicularstop01.wav	local

// Flexes [the most important parts :-) ]

flex		delay=1.2			local
flex		endelay=3.2			local
flex		kc=0				local
flex		wave=0				local
flex		once=0				local
flex		flexr=0
flex		flexg=150
flex		flexb=190

flex		en1=0				local
flex		en2=0				local
flex		en3=0				local
flex		en4=0				local
flex		en5=0				local
flex		en6=0				local
flex		en7=0				local
flex		en8=0				local
flex		en9=0				local
flex		en10=0				local
flex		en11=0				local
flex		en12=0				local
flex		en13=0				local
flex		en14=0				local
flex		en15=0				local

// Int's [for the KC]

int		enemy1				local		linkid=1
int		enemy2				local		linkid=1
int		enemy3				local		linkid=1
int		enemy4				local		linkid=1
int		enemy5				local		linkid=1
int		enemy6				local		linkid=1
int		enemy7				local		linkid=1
int		enemy8				local		linkid=1
int		enemy9				local		linkid=1
int		enemy10			local		linkid=1
int		enemy11			local		linkid=1
int		enemy12			local		linkid=1
int		enemy13			local		linkid=1
int		enemy14			local		linkid=1
int		enemy15			local		linkid=1

// The flash when new enemies arrive

template	appear0=-1			local
template	appear1=-1			local

// The cog to send message to when complete and for the kill points

cog		unlock
cog		ptsruntime

// The Player

thing       player                       local

// PTSRUNTIME.COG stuff

int killtemp local
flex deadnum=0 local

// Messages

message	startup
message	entered
message	killed									mask=0xfff

end

# ========================================================================================

code
startup:

   player = GetLocalPlayerThing();

Return;
//------------------------------------------------------------------------------------------------

entered:

if (GetSenderID()==0)
{
  if(once==0)
  {
once=1;

wave = 1;
enemy1 = CreateThing(oone, ghostoone);
CaptureThing(enemy1);
CreateThing(appear0, oone);
CreateThing(appear1, oone);

enemy2 = CreateThing(otwo, ghostotwo);
CaptureThing(enemy2);
CreateThing(appear0, otwo);
CreateThing(appear1, otwo);

enemy3 = CreateThing(othree, ghostothree);
CaptureThing(enemy3);
CreateThing(appear0, othree);
CreateThing(appear1, othree);

enemy4 = CreateThing(ofour, ghostofour);
CaptureThing(enemy4);
CreateThing(appear0, ofour);
CreateThing(appear1, ofour);

enemy5 = CreateThing(ofive, ghostofive);
CaptureThing(enemy5);
CreateThing(appear0, ofive);
CreateThing(appear1, ofive);

}
}

	Return;

//------------------------------------------------------------------------------------------------

killed:

if (GetThingHealth(player) > 0)
{
    kc=kc+1;
}

if(kc == enemiesin1)
{
sleep(delay);
wave=2;
enemy6 = CreateThing(tone, ghosttone);
CaptureThing(enemy6);
CreateThing(appear0, tone);
CreateThing(appear1, tone);
AddDynamicTint(player, flexr, flexg, flexb);
AddDynamicTint(player, flexr, flexg, flexb);
enemy7 = CreateThing(ttwo, ghostttwo);
CaptureThing(enemy7);
CreateThing(appear0, ttwo);
CreateThing(appear1, ttwo);

enemy8 = CreateThing(tthree, ghosttthree);
playsoundlocal(gensound0, 1, 0, 132);
playsoundlocal(gensound1, 1, 0, 132);
CaptureThing(enemy8);
CreateThing(appear0, tthree);
CreateThing(appear1, tthree);

enemy9 = CreateThing(tfour, ghosttfour);
CaptureThing(enemy9);
CreateThing(appear0, tfour);
CreateThing(appear1, tfour);

enemy10 = CreateThing(tfive, ghosttfive);
CaptureThing(enemy10);
CreateThing(appear0, tfive);
CreateThing(appear1, tfive);

}

if(kc == enemiesby2)
{
sleep(delay);
wave=3;
enemy11 = CreateThing(tho, ghosttho);
CaptureThing(enemy11);
CreateThing(appear0, tho);
CreateThing(appear1, tho);

enemy12 = CreateThing(tht, ghosttht);
CaptureThing(enemy12);
CreateThing(appear0, tht);
CreateThing(appear1, tht);
AddDynamicTint(player, flexr, flexg, flexb);
AddDynamicTint(player, flexr, flexg, flexb);
enemy13 = CreateThing(thth, ghostthth);
playsoundlocal(gensound0, 1, 0, 132);
playsoundlocal(gensound1, 1, 0, 132);
CaptureThing(enemy13);
CreateThing(appear0, thth);
CreateThing(appear1, thth);

enemy14 = CreateThing(thfo, ghostthfo);
CaptureThing(enemy14);
CreateThing(appear0, thfo);
CreateThing(appear1, thfo);

enemy15 = CreateThing(thfi, ghostthfi);
CaptureThing(enemy15);
CreateThing(appear0, thfi);
CreateThing(appear1, thfi);

}

if(kc == enemiesby3)
{
sleep(endelay);
playsoundlocal(stopsound, 1, 0, 132);
wave=4;
SendMessage(unlock, user0);
}

// **********************************************
// ** THIS IS JUST TO MAKE THE BREAK NOTICABLE **
// **********************************************

// Sends Messages to PTSRUNTIME.COG

if (en1==0)
{

if (GetThingHealth(enemy1)<=0)
{
en1=1;
killtemp = GetThingTemplate(enemy1);
deadnum=killtemp;
PrintFlex(deadnum);
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy2)<=0)
{

if (en2==0)
{
en2=1;
killtemp = GetThingTemplate(enemy2);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy3)<=0)
{

if (en3==0)
{
en3=1;
killtemp = GetThingTemplate(enemy3);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy4)<=0)
{

if (en4==0)
{
en4=1;
killtemp = GetThingTemplate(enemy4);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy5)<=0)
{

if (en5==0)
{
en5=1;
killtemp = GetThingTemplate(enemy5);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy6)<=0)
{

if (en6==0)
{
en6=1;
killtemp = GetThingTemplate(enemy6);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy7)<=0)
{

if (en7==0)
{
en7=1;
killtemp = GetThingTemplate(enemy7);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy8)<=0)
{

if (en8==0)
{
en8=1;
killtemp = GetThingTemplate(enemy8);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy9)<=0)
{

if (en9==0)
{
en9=1;
killtemp = GetThingTemplate(enemy9);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy10)<=0)
{

if (en10==0)
{
en10=1;
killtemp = GetThingTemplate(enemy10);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy11)<=0)
{

if (en11==0)
{
en11=1;
killtemp = GetThingTemplate(enemy11);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy12)<=0)
{

if (en12==0)
{
en12=1;
killtemp = GetThingTemplate(enemy12);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy13)<=0)
{

if (en13==0)
{
en13=1;
killtemp = GetThingTemplate(enemy13);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy14)<=0)
{

if (en14==0)
{
en14=1;
killtemp = GetThingTemplate(enemy14);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

if (GetThingHealth(enemy15)<=0)
{

if (en15==0)
{
en15=1;
killtemp = GetThingTemplate(enemy15);
deadnum=killtemp;
SendMessageEx(ptsruntime, user0, deadnum, -1, -1, -1);
}
}

return;
end


The recipient:

Code:
# Jedi Knight Cog Script
#
# PTSRUNTIME.COG
#

symbols

int enemy local
int killtemp local

flex deadnum local
flex points=0 local

message startup
message user0

end

# ========================================================================================

code
startup:

        SetPulse(0.25);
Return;

# ........................................................................................
user0:

  // Find out what enemy has been killed, then give the player a
  // specific amount of points for killing it.

  printflex(deadnum);

  if (deadnum==16)
  {
    points=points+4;
  }

  if (deadnum==22)
  {
    points=points+5;
  }

  if (deadnum==44)
  {
    points=points+10;
  }

PrintFlex(points);

Return;

end
2003-02-03, 10:07 AM #3
deadnum = GetParam(0);


The last four args of the SendMessage command are Params. They are retrieved in the recipient cog by "GetParam(n)", where n is the param number. In your case, it is param0.
And when the moment is right, I'm gonna fly a kite.
2003-02-03, 10:30 AM #4
fiu, nice cog [http://forums.massassi.net/html/smile.gif]
2003-02-03, 10:43 AM #5
thx, GBK

↑ Up to the top!