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.

AppGameKit Classic Chat / Get Number Of Seconds Since Game Was Run?

Author
Message
JeZxLee
7
Years of Service
User Offline
Joined: 15th Mar 2017
Location: Long Island, New York, United States, Earth
Posted: 17th Dec 2017 23:30
Hi,

Working on the playing game screen now.
How would I get the number of seconds since the game was first run?
It's for the game's timer when playing.

Thanks!
JeZxLee
16BitSoft
Video Game Design Studio
http://www.16BitSoft.com
Open-Source AppGameKit Project!

Attachments

Login to view attachments
JeZxLee
7
Years of Service
User Offline
Joined: 15th Mar 2017
Location: Long Island, New York, United States, Earth
Posted: 17th Dec 2017 23:33 Edited at: 17th Dec 2017 23:35
Hi Again,

I think I figured it out.
Game runs 30 FPS so every 30 frames is a second.
Thanks!
JeZxLee
16BitSoft
Video Game Design Studio
http://www.16BitSoft.com
Open-Source AppGameKit Project!
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 18th Dec 2017 02:39
A more proper way that is independent of the framerate would be to define a variable when you wish the timer to begin, e.g.



And then within the loop you can get the total elapsed time using:



This will return a float in seconds. If you are using this in functions you'll want to define the startTime# variable globally so it is accessible.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th Dec 2017 09:01
Quote: "elapsedTime# = Timer() - startTime#"

This isn't needed, since Timer() returns the number of milliseconds since the game was started, which is exactly what the OP wanted. Use ResetTimer() to, well reset the timer. lol

Look at the help file here
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 18th Dec 2017 09:14
Quote: "This isn't needed, since Timer() returns the number of milliseconds since the game was started"

True if the game's action begins immediately but most games will have loading or menu screen etc so xcepts method is more useful.
It's also needed if the game has a pause option.
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Markus
Valued Member
19
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 18th Dec 2017 11:00
you can also add GetFrameTime() by yourself
AGK (Steam) V2017.12.12 : Windows 10 Pro 64 Bit : AMD (17.12.1) Radeon R7 265 : Mac mini OS High Sierra (10.13)
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 18th Dec 2017 18:21
Quote: "This isn't needed, since Timer() returns the number of milliseconds since the game was started, which is exactly what the OP wanted."


I disagree. OP is looking to track "the game's timer when playing" specifically on the "playing game screen" such as a countdown as seen in his screenshot. Although you could technically use the raw Timer() and resetTimer() approach, you'll have much less control than you would by simply tracking it via a few user variables. Also if Timer() is being used for anything else in the app, resetting it strictly to track the game play time can have undesirable consequences elsewhere.
JeZxLee
7
Years of Service
User Offline
Joined: 15th Mar 2017
Location: Long Island, New York, United States, Earth
Posted: 18th Dec 2017 19:38
Hi,

I got it working already!
Game will be playing before December 18th is over!
JeZxLee
16BitSoft
Video Game Design Studio
http://www.16BitSoft.com
Open-Source AppGameKit Project!
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 18th Dec 2017 22:52
Quote: " xcepts method is more useful"

xCepts way is how I would have done it too

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
puzzler2018
User Banned
Posted: 18th Dec 2017 22:54
that method is also a way to be able to trigger things to happen

Is good method to learn
puzzler2018
User Banned
Posted: 18th Dec 2017 23:04
Its best not to come away from the question in hand though - FPS is all it was about lol
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 19th Dec 2017 10:05
Quote: " Use ResetTimer() to, well reset the timer. lol"

I'll repost this, since it looks to have been ignored.....
LillyByte
6
Years of Service
User Offline
Joined: 30th Oct 2017
Location:
Posted: 19th Dec 2017 15:38
If you're looking at a strict way of getting elapsed seconds...

Wouldn't the most effective way of doing this would be use the GetSeconds() command?

Then subtracting another GetSeconds() at any time to determine how many seconds have passed at any point?
~~ LillyByte ~~
http://www.dymoria.com

Login to post a reply

Server time is: 2024-03-29 08:34:10
Your offset time is: 2024-03-29 08:34:10