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 / Helped needed converting decimal seconds to hours/min/sec

Author
Message
DemonHill
16
Years of Service
User Offline
Joined: 20th Mar 2008
Location:
Posted: 21st Sep 2013 23:18 Edited at: 21st Sep 2013 23:20
I am trying to convert some DB Pro Code functions to give me a function in AppGameKit to convert a decimal number i.e. 97 to hours-mins-secs-10th sec

Here's what works in DB Pro, anyone got a function for AppGameKit ?



The Zoq2
14
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 21st Sep 2013 23:27
What I would do is something like this



I have no idea if the code will work, but the basic idea is that the amount of hours is the seconds divided by the amount of seconds in an hour (3600). Then you count the remaining seconds without the hours using the Mod() function.

Say ONE stupid thing and it ends up as a forum signature forever. - Neuro Fuzzy
AgentSam
12
Years of Service
User Offline
Joined: 14th Mar 2012
Location: Virtual Space
Posted: 22nd Sep 2013 16:32 Edited at: 22nd Sep 2013 17:00
Quote: "I am trying to convert some DB Pro Code functions to give me a function in AppGameKit to convert a decimal number i.e. 97 to hours-mins-secs-10th sec"


Based on what you wrote, I'm going to have to make a few assumptions. It seems that you're not interested in displaying a "clock", but are instead trying to display an amount of time, such as a laptime.

Further, I'm going to assume that your decimal number will be an amount of time in milliseconds, as that's what the example function you posted uses.

Quote: "Here's what works in DB Pro, anyone got a function for AppGameKit ?"


AGK does not recognize the Str$() function, so all you really need to do, is replace it by Str(), and it compiles.

Note that the example function is not useful as a generic clock display, because it's purely incremental - but it could be useful to display a laptime.

Here's the fixed example that compiles in AGK.



However, the above function is rather badly coded... (I assume it was taken from the DB Pro forum.) There's no need for any of those while-loops and the bunch of if-statements. The snippet posted by "Zoq2" was on the right track, but definately not functional.

Here's how I would do it. (Check out the functions at the end of the code.)



Also noteworthy: Because AppGameKit stores integers as 32-bit signed values, the largest number of milliseconds we can represent using them, is 2147483647. That translates to 596 hours, 31 minutes, 23 seconds, and 647/1000 of a second.


Cheers,
AgentSam
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 23rd Sep 2013 05:08
Here are some functions I made a few weeks ago for one of my apps
They get Hour/Minute/Seconds from the number of seconds.
ie. GetHour(70)="0", GetMinute(70)="01", GetSeconds(70)="10"
GetHour(3602)="01", GetMinute(3602)="0", GetSeconds(3602)="02"
They return a string, not an integer, but they'd be easy to change if you want



AgentSam
12
Years of Service
User Offline
Joined: 14th Mar 2012
Location: Virtual Space
Posted: 23rd Sep 2013 08:29
@MissJoJo:

Wouldn't this make more sense? These routines are also faster.



Cheers,
AgentSam
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 23rd Sep 2013 11:51
AgentSam,
Probably, but speed wasn't really my main concern when I wrote them, they were/are only called once every so often.
So I didn't really spend much time on them.

Your signature has been erased by a mod
AgentSam
12
Years of Service
User Offline
Joined: 14th Mar 2012
Location: Virtual Space
Posted: 23rd Sep 2013 14:07
Offtopic: Wait... weren't you MissJoJo? Did MissJoJo just become the easter bunny?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 23rd Sep 2013 14:27 Edited at: 23rd Sep 2013 14:40
Quote: "Offtopic: Wait... weren't you MissJoJo? Did MissJoJo just become the easter bunny?"

I have changed easter bunny's signature to say "formerly MissJoJo" in future posts and would ask that it remains for the near future.

EDIT: Further information on Forum Name Changing

You can never have too much sausage
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 23rd Sep 2013 14:53
As to padding routines, here's a cute one I picked up many years ago;

It's really for integers less than 999,999,999, so it should handle times ok
and of course the one for spaces

Again for Integers, but it isn't much more to include floats
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 24th Sep 2013 04:09
Quote: "I have changed easter bunny's signature to say "formerly MissJoJo" in future posts and would ask that it remains for the near future."

Just a quick off-topic question, how big can my sig be?

I've brought it down to 200x60 (from 500x150)


formerly MissJoJo - Audacia Games
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Sep 2013 10:06
600x120 is the maximum size allowed.

Parragil para o mundo!
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 24th Sep 2013 18:21
While looking for some other code in an old project, I came across this;

Passed a float containing seconds, and a number of decimal places, it produces the output
D;HH:MM:SS.ssss.

It's pretty much the same as the others posted, but with days and bits of seconds.

Still haven't found the code I'm looking for though

Login to post a reply

Server time is: 2024-05-09 15:34:22
Your offset time is: 2024-05-09 15:34:22