PDA

View Full Version : Cog Multiplayer Problem


Shockaz
08-18-2004, 01:28 PM
The original coding was by Edward, but I made a few modifications to it, and now the cog doesn't work the way I want it to. Basically, when a player steps on a switch, nothing happens, but when the other player steps on the other switch, the stairs should be moving to their 2nd frame. The problem is that the stairs go to their 2nd frame when one player steps on a switch. Why does it do this, and how do I fix it?


symbols

message startup
message entered
message exited

thing switch1
thing switch2

thing stair01
thing stair02
thing stair03
thing stair04
thing stair05
thing stair06
thing stair07
thing stair08
thing stair09

int status=0 local
flex speed=1

end
#---------------------------
code
#---------------------------
startup:

MoveToFrame(stair01, 0, 100);
MoveToFrame(stair02, 0, 100);
MoveToFrame(stair03, 0, 100);
MoveToFrame(stair04, 0, 100);
MoveToFrame(stair05, 0, 100);
MoveToFrame(stair06, 0, 100);
MoveToFrame(stair07, 0, 100);
MoveToFrame(stair08, 0, 100);
MoveToFrame(stair09, 0, 100);

return;
#---------------------------
entered:

if((GetSenderRef() == switch1) && (status == 0 || status == 2))
status = status + 1;
else if((GetSenderRef() == switch2) && (status == 0 || status == 1))
status = status + 2;
else return;
if(status == 3)

MoveToFrame(stair09,1,speed);
MoveToFrame(stair08,1,speed);
MoveToFrame(stair07,1,speed);
MoveToFrame(stair06,1,speed);
MoveToFrame(stair05,1,speed);
MoveToFrame(stair04,1,speed);
MoveToFrame(stair03,1,speed);
MoveToFrame(stair02,1,speed);
MoveToFrame(stair01,1,speed);

return;
#---------------------------
exited:

if((GetSenderRef() == switch1) && (status == 1 || status == 3))
status = status - 1;
else if((GetSenderRef() == switch2) && (status == 2 || status == 3))
status = status - 2;
else return;

MoveToFrame(stair01,0,speed);
MoveToFrame(stair02,0,speed);
MoveToFrame(stair03,0,speed);
MoveToFrame(stair04,0,speed);
MoveToFrame(stair05,0,speed);
MoveToFrame(stair06,0,speed);
MoveToFrame(stair07,0,speed);
MoveToFrame(stair08,0,speed);
MoveToFrame(stair09,0,speed);

return;
#---------------------------
end


------------------
Pumpkins are the only living organisms with triangle eyes.

darthslaw
08-18-2004, 05:16 PM
Problem lies in the "entered" message -- after "if(status == 3)", the MoveToFrame()'s should be enclosed by braces, because currently, only the first one is (if statement's "imaginary" braces) while the rest will always be executed.
But I think I may have given him (or someone) that code some time ago well, I'm half right by this statement http://forums.massassi.net/html/wink.gif -- it was the same concept except it was for a door opened by the 2 switches, and the "status" use is used like I remember using it.

Heh, whether it is or not, I made some changes to the code you presented, because that one has a bug that will close the steps if someone steps off the switch (regardless of if there is still someone on it). This updated version will keep track of how many people are on each switch and when the LAST person steps off, THEN it will close. It also keeps track of the status slightly differently (boolean is way easier and can more easily be modified http://forums.massassi.net/html/smile.gif )

[edit](okay, did some searching -- it's Edward's but I modified it a bit here (http://forums.massassi.net/html/Forum4/HTML/004022.html) http://forums.massassi.net/html/smile.gif, which is your thread)

symbols

message startup
message entered
message exited

thing switch1
thing switch2

thing stair01
thing stair02
thing stair03
thing stair04
thing stair05
thing stair06
thing stair07
thing stair08
thing stair09

# Keep track of whether the steps are out
int status1=0 local
int status2=0 local

# Keep track of how many ppl are on each switch (in case one of 2 ppl gets off -- don't put steps away)
int count1=0 local
int count2=0 local

flex speed=1
int i local

end

code

startup:
for(i = 0; i < 9; i = i + 1) MoveToFrame(stair01[i], 0, 100);

return;

entered:
if(GetSenderRef() == switch1) //switch1
{
count1 = count1 + 1; //one more person on switch
if(!status1) status1 = 1; //if not active, activate
else stop; // else, don't open them again
}
if(GetSenderRef() == switch2) //switch2
{
count2 = count2 + 1; //one more person on switch
if(!status2) status2 = 1; //if not active, activate
else stop; // else, don't open them again
}
else stop; //failsafe in case a step sent the message

if(status1 && status2) //both switches active
for(i = 0; i < 9; i = i + 1)
MoveToFrame(stair01[i], 1, speed);

return;

exited:
if(GetSenderRef() == switch1) //switch1
{
count1 = count1 - 1; //one less person on switch
if(count1 <= 0) status1 = 0; //nobody left on step -- close up
else stop; // else, still someone on step -- don't close
}
if(GetSenderRef() == switch2) //switch2
{
count2 = count2 - 1; //one less person on switch
if(count2 <= 0) status2 = 0; //nobody left on step -- close up
else stop; // else, still someone on step -- don't close
}
else stop; //failsafe in case a step sent the message

if(!status1 || !status2) //if either switch is off -- close steps
for(i = 0; i < 9; i = i + 1)
MoveToFrame(stair01[i], 0, speed);

return;

end


------------------
nytfyre m0d (http://www.nightfire.uni.cc/site/page.php) || f33l t3h p0w3r (http://www.geocities.com/qrphome/pwp3/) || t3h l0st c0gz (http://www.tbns.net/GBK/ol/index.htm) || OMF > * (http://www.bkkbazaar.com/omf/)

[This message has been edited by Darth Slaw (edited August 18, 2004).]