Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Simple countdown timer -- help needed

Author
Message
MightyRy
13
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 27th Oct 2010 13:23
Im not sure where to start.

i want a simple timer for my game which counts down from 10 minutes displaying minutes and seconds!

Anyone know the code?

Posting it will be great!!!!

Thanks
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Oct 2010 20:17
You take a snapshot of the current timer, add your required elapsed time to it, then continually check how far away from that target time you are - add a bit of basic pretty-formatting to the time (convert to mins, secs etc), and there you are.

There's an example I posted years ago in the codebase.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
Lord Einstein
18
Years of Service
User Offline
Joined: 22nd Oct 2005
Location: Well here, of course...
Posted: 27th Oct 2010 23:41
Try this:

MightyRy
13
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 19th Nov 2010 10:42
thanks for the code.

I have recently tried adding, once the the countdwon finished it goes to a function but the countdown just stops at 0:1 annoyingly. run the code and you will see what i mean. Whats wrong?

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 22nd Nov 2010 17:41
You aren't using "sync" in your credits function...

Try it like this:


MightyRy
13
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 27th Dec 2010 22:47
If i want my game to end when the clock is 0 min and 0 secs what do i need to do

At the moment i have the code below and as soon asx the level begins it goes to the outoftime()

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 28th Dec 2010 05:35 Edited at: 28th Dec 2010 05:55
Here is a quick timer example:


How it Works:
OldTime# - Stores PerfTimer
PerfTimer - Gets the time since the computer was turned on.
"(PerfTimer() - OldTime#)" - By getting the difference between the time now and the start time you get the current time.
"OldTime# = PerfTimer()" - Will reset the timer
GetFreq() - To increase the timers accuracy.
StartTime# - The start time of the count down

DigitalFury
MightyRy
13
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 28th Dec 2010 16:10
Is ther nothing i can do with the timer i got?

I just want to know why using this..




Makes the outoftime function (an end game scenario) appear as soon as the game starts and doesnt even count down!
DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 28th Dec 2010 21:25 Edited at: 28th Dec 2010 23:00
@MightyRy -

Quote: "Is ther nothing i can do with the timer i got?"

Could you post your code. I can't find it. Thanks

I can explain what I got a bit more though:

If your ending the game then just replace this:



With this:



or using Baxslash's credits function:



Baxslash's credits function:


The code I gave you should work just fine.

This line will set current time to the start time which is 10 minutes and subtract the minutes.


If you want to count down 10 seconds then use this:


If you want to count down 10 hours then use this:


If you want to count down 10 MiliSeconds then use this:


I posted a tutorial for you to make things easier:
http://forum.thegamecreators.com/?m=forum_view&t=178927&b=1&p=0

Let me know if you need any help.

DigitalFury
MightyRy
13
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 29th Dec 2010 16:38 Edited at: 29th Dec 2010 16:51
Here is my clock function, above the function is variables




As i have said i want the game to end once it has finished counting down.

with this code



The program enters stright into the outoftime ()

In my DO-LOOP i now have this to go to the out of time scenario



it now counts down but doesnt go the outoftime function when the timer is 0 : 0!
DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 29th Dec 2010 22:04 Edited at: 30th Dec 2010 02:00
Couldn't figure out exactly what is wrong with your code. I would need all of it to figure it out.

Here is a cleaned up example:


Hopefully that helps!

DigitalFury
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 1st Jan 2011 15:01
Quote: "it now counts down but doesnt go the outoftime function when the timer is 0 : 0! "


Hmm.... I don't see currtime# being manipulated anywhere in your clock() function. How is it counting down?


Guns, cinematics, stealth, items and more!
MightyRy
13
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 4th Jan 2011 16:29 Edited at: 4th Jan 2011 16:31
sorry currtime# is used for a different function.

so my clock function and the variables are:



And in the main do loop is:



AS i have said before, the game exits to the outoftime function instatntly. So the clock must set itself to 0, then set the 3 minutues after and that is why it is escaping.
Agent
20
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 11th Jan 2011 16:24
Seems much more likely that CurrentTime# is never being set to anything, or at least you're checking that it's <= 0 before you set it to something nonzero.

Even if you are setting it to something correctly, make sure it's a global variable and not a local one, otherwise clock() won't be able to access its contents and it'll treat it as zero, which triggers your IF...THEN check.

If these suggestions don't help, we'll need your complete code - every line, even the unrelated functions, so we can do a proper logic trace and help you track down the bug. If you skip any part of your program when you paste it to us, we can't help you any further.

Login to post a reply

Server time is: 2024-09-29 00:26:18
Your offset time is: 2024-09-29 00:26:18