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.

DarkBASIC Professional Discussion / I need help with a game clock

Author
Message
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 20th Jun 2003 19:09
I need to develop a clock for my game. It needs to start at 8am 1st Jan 2003. I would like 1 realtime minute to equal 1 gametime hour. I need it to be constantly displayed on the same part of the screen. I will need to use the clock not only so the player knows the 'game world time' but also to trigger mission events, etc. Can anyone help coz I have not got the faintest idea where to start!
Life is like a penis:
When it's soft you can't beat it, when it's hard you get screwed.
andrew11
23
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 20th Jun 2003 19:27
Do you want it to continue only when you play the game or even when you are not?

"All programmers are playwrites and all computers are lousy actors" -Anon
Click Here!!!
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 20th Jun 2003 19:44 Edited at: 20th Jun 2003 19:45
When you save the game...i'd like it to remember the time so that it can carry on from there. My save game is a 3d array with a tonne of space left to stick in some variables required by the clock

When you pause....it would be great if the clock paused also

How can this be done?

Life is like a penis:
When it's soft you can't beat it, when it's hard you get screwed.
iaretony
23
Years of Service
User Offline
Joined: 6th Jun 2003
Location:
Posted: 20th Jun 2003 20:15
So, 1 second equals one minute? That's easy...

Every time through you're loop check to see whether it has been a second since you last updated the clock, if so, update it...

timer() - returns milliseconds (thousandths of a second)...

andrew11
23
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 20th Jun 2003 20:21
First, you do what iaretony said:



Then, you convert it to seconds, then use it as minutes:


You just have to worry about saving it to a file. You should encrypt it somehow so users cannot change it.

"All programmers are playwrites and all computers are lousy actors" -Anon
Click Here!!!
SirReal
23
Years of Service
User Offline
Joined: 20th May 2003
Location:
Posted: 20th Jun 2003 21:09
Here

This will do what you want. It does NOT account for leap years, do that yourself.

SirReal
23
Years of Service
User Offline
Joined: 20th May 2003
Location:
Posted: 20th Jun 2003 21:35
Whoops, typo. Use this code instead

FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 20th Jun 2003 21:58
Thankyou SirReal!!! Very much appreciated!!

I have one problem including it in my code though (I had devised a worse one than you came up with and had the same problem).

Essentially my game engine has 3 main functions in a loop:



I figured I would simply have to put the clock in this loop. However, in CheckConsoleInputs() there is an INPUT command and the clock is not updated on the screen until after the user presses the enter key...this is a big problem because my game is, essentially a text game and this INPUT pops up every cycle of the loop...if the clock doesnt update until the user presses RETURN then its no good. How can I get around this?

Life is like a penis:
When it's soft you can't beat it, when it's hard you get screwed.
andrew11
23
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 20th Jun 2003 22:20
You can add this for leap years:



"All programmers are playwrites and all computers are lousy actors" -Anon
Click Here!!!
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 20th Jun 2003 22:23
Essentially, Console() Draws the screen and 'writes' the content of an array to the screen (the array containing inputs from the player and outputs from the game).

CheckConsoleInputs() prompts the user to enter something and then this variable is sent to ProcessCommands() where something is done and the loop then repeats.

It seems to me that because of this INPUT command, the loop 'stalls' at this point and, hence, the clock cannot be updated on the screen (although when the clock does get updated, after the user has pressed the RETURN key, it has kept the correct time).

Life is like a penis:
When it's soft you can't beat it, when it's hard you get screwed.
the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 20th Jun 2003 23:15
Insted of using the inbuilt input you could try writeing your own input function that had a loop in it that updated the onscreen time as well as showed what had been typed.
SirReal
23
Years of Service
User Offline
Joined: 20th May 2003
Location:
Posted: 20th Jun 2003 23:46
It would take a little fiddling, but take the code below and use it inside a while loop to check for text, that way you can keep syncing the screen.

while gottext$ = ""




dowhile

SirReal

SirReal
23
Years of Service
User Offline
Joined: 20th May 2003
Location:
Posted: 20th Jun 2003 23:55
Whoops, forgot to mention that I didn't write that code, got it off the snippets board a while ago.

FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 21st Jun 2003 01:39 Edited at: 21st Jun 2003 19:44
Thanks,
I took your excellent clock function and a realtime input function from (I think RobK....I'll check) and combined them together to get it to work. Thankyou for all your help.



Life is like a penis:
When it's soft you can't beat it, when it's hard you get screwed.

Login to post a reply

Server time is: 2026-07-11 14:56:15
Your offset time is: 2026-07-11 14:56:15