Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timing the duration of a game.
#1
Greetings everyone, I was just wondering if there was a way to time the duration that a game has been going on. For instance:

Say you start the RPG that I made (If I made one, just pretend with me) and choose NEW GAME... well, from that point on (while you are still playing) I want a 'timer' to be going that tells you how long that you've been playing (such as all the 'commercial' RPG games have)

I have ... erhem, attempted to do such a feat but I have yet to figure out how it was done........I figured it would have to be something pertaining to the TIMER function, but since it is all askewed, I don't know how to display it.... If you just said

Code:
timeplayed = timer
print "You have played "; timeplayed
it would come out as some strange number so I don't know what to do, I am sure that this is an easy question with an easy answer or something like that but I just haven't figured it out (or haven't tried hard enough)

Any help would be appreciated.

-Nova
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#2
yeah, TIMER.

Although TIME$ is better for such a thing. But you probably won't be playing for more than a day.

The idea is to subtract the end time from the start time. Thus you have the amount of time in between.

t1 = TIMER
'do stuff.....
t2 = timer
t3 = t2 - t1
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
I get what you mean.
BTW the TIMER function returns how many seconds have passed since midnight...
I've been trying the same thing...I can't get it! :/
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#4
Here's one way to get the timer to look more "clock-like":

Code:
CLS
DO
  t = INT(TIMER)
  th = INT(t / 3600)
  tm = INT((t - (th * 3600)) / 60)
  ts = INT(t - ((th * 3600) + (tm * 60)))
  hours$ = RIGHT$(STR$(th), 2)
  minutes$ = RIGHT$(STR$(tm), 2)
  seconds$ = RIGHT$(STR$(ts), 2)
  LOCATE 6, 4: PRINT USING "&:&:&";hours$ ;minutes$ ;seconds$
  LOCATE 8, 4: PRINT "Hit any key to continue . . ."
LOOP UNTIL INKEY$ <> ""
END

Modify it however fits your needs.

Dex
Reply
#5
Yeah but that still really doesn't answer my question... is there a way?

Quote:Agamemnus wrote:
Although TIME$ is better for such a thing. But you probably won't be playing for more than a day.


NO! Time$ is the system clock so if you reset time$ then the clock resets too!! argh, anyway if someone could explain to me how to do it in 'newbies terms' that would be great cause as of now I don't get it!
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#6
Eh or right.. right.. u could use DATE$ instead of TIMER I meant. Smile

Ok then newbie, so then you have to save t3 every time and keep adding. Is that what you want?

What do you want?

Edit: oh and... add this:

IF t1! > t2! then t3! = t2! - t1! - 86400 else t3! = t2! - t1!

Or somethin Smile

Another EDIT: You don't need to reset anything, just get the difference. :roll:
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#7
Ok, well all you have to do is, when the game starts set a "start" value:
start = timer
Then at whatever interval you want take a new reading:
present = timer
then, elapsed = present - start
then substitute the value "elapsed" in the place of "t" in my above code to get it into "clock" mode, and display it where ever you want.

It could look like this:

Code:
start = timer
.
.   Your game code
.   goes here!
.
present = timer: GOSUB DisplayTime
print clock$
.
.
END

DisplayTime:
  t = INT(present - start)
  th = INT(t / 3600)
  tm = INT((t - (th * 3600)) / 60)
  ts = INT(t - ((th * 3600) + (tm * 60)))
  hours$ = RIGHT$(STR$(th), 2)
  minutes$ = RIGHT$(STR$(tm), 2)
  seconds$ = RIGHT$(STR$(ts), 2)
  clock$ = hours$ + ":" + minutes$ + ":" + seconds$
  RETURN

Dex
Reply
#8
:evil: is there anyway that i can make the program end when a timer runs out :evil:
evil: tell me if this hurts :evil:
Reply
#9
i recomend not to bring topics back from the dead but to answer your questions yes.

http://faq.qbasicnews.com/?blast=TimerTopics

look at delaysecs
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#10
:evil: how? :evil:
evil: tell me if this hurts :evil:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)