PDA

View Full Version : Why does it print at the wrong time?



Edward
09-14-2003, 12:55 PM
Hi!
This COG, when lever activated, releases endless grenades, until lever is pressed again.


# Grenades at Jump challange!
#
# By Edward

symbols

message activated
message pulse

surface lever

sound announce

thing place0
thing place1
thing place2
thing place3
thing place4
thing place5
thing place6
thing place7
thing place8
thing place9
thing place10
thing place11
thing place12
thing place13
thing place14
thing place15

template grenades

int i=0 local
int z=0 local
int go=0 local

end
#
code
activated:
If(GetSenderRef()!=lever) return;
if(go==0) {
PlaySoundGlobal(announce,1,0,0xC0);
Print("A challange is being thrown at the oily bronze corse.");
SetPulse(0.16);
SetWallCel(lever,1);
go=1;
sleep(5);
print("Can you jump through 16 grenades/0.01 seconds?");
} else {
print("Grenades have stopped...");
SetPulse(0);
SetWallCel(lever,0);
go=0; }
return;
pulse:
for(i=0; i<16; i=i+1) {
CreateThing(grenades,place0[i]);
sleep(0.01); }
return;
end

The problem is that when I "deactivate" the lever, it says "Grenades have stopped..." and then a little while after it says "Can you jump through 16 grenades/0.01 seconds?", and it doesn't say "Can you..." after I activate the lever. Help!

/Edward

DSLS_DeathSythe
09-14-2003, 02:48 PM
try this and see if it fixes it.

//-When you set the pulse do this...
i = 0;
SetPulse(0.01);
#----------
//-Make the pulse message like this...
pulse:
CreateThing(grenades, place0[i]);
i = i + 1;
if(i > 15) i = 0;
return;

------------------
Famous last words - "It seemed like a good idea at the time."

SaberMaster
09-14-2003, 03:22 PM
Yeah, do what DeathSythe suggested for the pulse, and use an IDed timer instead of the five-second sleep. That way, you won't have any thread problems, and you'll be able to use KillTimerEx() to stop the message from printing if the surface is activated again before the five seconds are up.

------------------
Author of the JK DataMaster (http://www.geocities.com/sabersdomain/files.html), Parsec (http://www.geocities.com/sabersdomain/files.html), Scribe (http://www.geocities.com/sabersdomain/files.html), and the EditPlus Cog Files (http://www.geocities.com/sabersdomain/files.html).

Edward
09-15-2003, 06:56 AM
Thank you! All is OK!

/Edward