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 → Timed Level
Timed Level
2002-02-13, 10:17 AM #1
How do I implement a timer in a level that will restart the level if all of the goals are not completed within the time limit?

Also, is it possible for a clock of some kind to appear on the screen that counts down? This latter part would be nice, but is not required.

------------------
Dead Reckoning and Dead Reckoning 2
Dead Reckoning
2002-02-13, 10:22 AM #2
Should be fairly easy to write a cog that begins at startup, has a sleep statement like sleep(leveltime); then the cog checks if all the goals are achieved. If not the level restarts.

I think someone did make a clock already. Would take a cog and a set of multi-frame mats with the numbers on them.

------------------
Sylvicolus JK homepage
If I have ever made any valuable discoveries, it has been owing more to
patient observation than to any other reason. -Isaac Newton
Sylvicolus JK homepage
If I have ever made any valuable discoveries, it has been owing more to
patient observation than to any other reason. -Isaac Newton
2002-02-13, 12:32 PM #3
Have a look at the cogs for the falling ship LEC level. It has a timer doing exactly what you want.

Raynar


------------------
... the Jedi I admire the most, met up with Darth Maul, now he's toast ...
Rbots - a project to develop a working Bot for Jedi Knight... download the latest development version here
Pagewizard_YKS: "making your own lightsaber doesn't make you a nerd... "
Raynar - the man with a 10.75" ePenis
2002-02-13, 4:33 PM #4
Its been awhile since Ive done a timer system. This was fun. [http://forums.massassi.net/html/wink.gif]


Code:
# Simple script for a count-down system imposed on a set of objectives.
#
# User7 will stop the timer.
#
# 02/2002 GBK
Symbols
Message Startup
Message Pulse
Message Timer
Message User7
Thing Player						Local
Int Goal_num0=0
Int Goal_num1=1
Surface Mins0
Surface Mins1
Surface Secs0
Surface Secs1
Int Mins_0
Int Mins_1
Int Secs_0
Int Secs_1
Int End_flash=0	#Create a burst of white light/sound if failed?    0 = no.
Sound End_sound
Int I=0						Local
End
Code
Startup:
Player = JKgetlocalplayer();
Sleep(1);
Setpulse(1);
Call Set_surf;
Stop;
Pulse:
Secs_0 = Secs_0 - 1;
If(Secs_0 == -1) {
If(Secs_1 != 0 || Mins_0 != 0 || Mins_1 != 0) { Secs_0=9; Secs_1 = Secs_1 - 1; }
Else { Call Killer; } }
If(Secs_1 == -1) { If(Mins_0 != 0 || Mins_1 != 0) { Secs_1=5; Mins_0 = Mins_0 - 1; } }
If(Mins_0 == -1 && Mins_1 != 0) { Mins_0=9; Mins_1 = Mins_1 - 1; }
Set_surf:
For(I=0;I<2;I=I+1) {
Setwallcel(Mins0, Mins_0);
Setwallcel(Secs0, Secs_0); }
Stop;
Killer:
Setpulse(0);
If(Getgoalflags(Player, Goal_num0) == 2 && Getgoalflags(Player, Goal_num1) == 2) Stop;
If(End_flash != 0) { 
Newcoloreffect(0, 0, 0, 0, 0, 0, 256, 256, 256, 1.0); 
Playsoundlocal(End_sound, 1, 0.0, 0x4); }
Sleep(1);
JKendlevel(0);
Stop;
User7:
Setpulse(0);
For(I=0;I<2;I=I+1) { 
Setwallcel(Mins0, 0); 
Setwallcel(Secs0, 0); }
Stop;
End




Ok, the variables are kinda strange..


Goan_numX   -   The goal numbers for your goals. It should work with the defualt settings.


MinsX - Read below.

SecsX - Read below.


Mins_0 - The first digit of the number of minutes. (0x:00)

Mins_1 - The second digit of the number of minutes. (x0:00)

Secs_0 - The first digit of the number of seconds. (00:0x)

Secs_1 - The second digit of the number of seconds. (00:x0)


End_flash - If set to anything other than 0, will create a white flash and play a sound when the level is failed.


BTW, to get the level to restart via this cog, set the 'GotoB' in your episode manager to the same line as the level. (In other words, if the line # of the level is 10, set 'GotoB' to 10)


It works, I tested it. Credit me. [http://forums.massassi.net/html/biggrin.gif]

------------------
Success is the inverse relationship between effort, gain, and loss.

[This message has been edited by GBK (edited February 13, 2002).]
And when the moment is right, I'm gonna fly a kite.
2002-02-13, 5:58 PM #5
GBK - once again: Loops are good when you want to repeat an action. By this I mean, like, 50 times - not once or twice.

And, please: I don't mean to get into a religious debate about code formatting, but the Microsoft standard is very, very clean-looking. This is a COG help forum. Your code is gibberish, albeit useful gibberish.
2002-02-13, 6:41 PM #6
Quote:
<font face="Verdana, Arial" size="2">Originally posted by Jon`C:
...but the Microsoft standard is very, very clean-looking. This is a COG help forum. Your code is gibberish, albeit useful gibberish.</font>



It doesnt matter what the code looks like. I have never intended anyone to actully READ my cogs. Ever. If I have, I would throw commenting into the code, and space it out a little.

These cogs are meant to be used, not scrutinized for thier functionality.

 


And, Microsoft standard? [http://forums.massassi.net/html/confused.gif]

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-02-13, 7:52 PM #7
He shoulda said programming standard. [http://forums.massassi.net/html/smile.gif]

COBALT (I think) had tabs way before BASIC was invented. [http://forums.massassi.net/html/smile.gif]
-Hell Raiser
2002-02-13, 9:55 PM #8
Microsoft-standard format. If you look at any Microsoft code, it generally follows these rules: Statements are always on a new line, compound statement braces are always on their own line.

Second... could you please explain why you insist upon using excessively redundant for loops? Once again - this is just horrific code. You didn't seem to respond to my argument in the other thread, so I'll try again. If you want to avoid scrutiny - on a COG help forum - justify your solution. It disturbs me that you are providing such unhealthy code to people who need COG help.
2002-02-14, 6:49 AM #9
The cog works, thats all that really matters.

Perhaps I should make something very clear, I am not a programmer. COG is the only language I know. I have no experiance in anything else.


 

Quote:
<font face="Verdana, Arial" size="2">Originally posted by Jon`C:
GBK, you really like arrays, don't you? [http://forums.massassi.net/html/smile.gif]</font>



Yes, yes I do...

------------------
Success is the inverse relationship between effort, gain, and loss.

[This message has been edited by GBK (edited February 14, 2002).]
And when the moment is right, I'm gonna fly a kite.
2002-02-14, 6:52 AM #10
BTW, would you mind defining 'unhealthy code'?

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-02-14, 6:58 AM #11
Specifically, I was referring to totally unnecessary loops. Ordinarily your COG could be useful as an example, or even for the base of another COG. The loops serve no real purpose except to confuse and confound the person looking at it. It's too much of a good thing.
2002-02-14, 7:03 AM #12
Quote:
<font face="Verdana, Arial" size="2">Originally posted by GBK:
I have never intended anyone to actully READ my cogs. Ever.</font>




------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.

↑ Up to the top!