GameSalad

How can make a count up timer that shows Hours, Minutes, Seconds & Milliseconds?

Dell7730Dell7730 Posts: 388Member, PRO
edited July 2015 in Working with GS (Mac)

it would be in this format of two digits each 00:00:00:00 or maybe 00:00:00:0 with just one digit for the milliseconds

I'm making a simple puzzle game and I would like to time how long or fast it took to solve the puzzle.

Best Answers

Answers

  • Dell7730Dell7730 Posts: 388Member, PRO

    @Socks said:
    padInt( game.Clock.Hour ,2)..":"..padInt( game.Clock.Minute ,2)..":"..padInt( game.Clock.Second ,2)..":"..padInt(round( game.Clock.Millisecond /10),2)

    it sez Invalid Expression, lol

  • SocksSocks London, UK.Posts: 12,725Member

    @Dell7730 said:
    it sez Invalid Expression, lol

    Can you upload a screenshot of the expression.

  • Dell7730Dell7730 Posts: 388Member, PRO

    @Socks said:
    Can you upload a screenshot of the expression.

    Just kidding, I got it, thanks again Sir!

  • Dell7730Dell7730 Posts: 388Member, PRO

    @tintran said:
    You can use the game.Time or self.Time(actor variable) to get number of seconds have passed, and then do your own math, to figure out hours,minutes,seconds,milliseconds
    like
    to get hours: padInt(floor(game.Time/3600),2)
    to get minutes: padInt(floor((game.Time%3600)/60),2)
    to get seconds: padInt(floor(game.Time%60),2)
    to get hundredths of seconds: padInt(floor(game.Time*100%100),2)

    then you can join them all together using ..":"..

    the .. just joins strings together. and the colon (:) is in quotes for the whole thing to work.

    If you want to set your own start_time to save game.Time or self.Time then when the puzzle is solved you can set your own end_time to save game.Time or self.Time..
    and subtract start_time from end_time should give you number of seconds that took to solve the puzzle and you can use this number of seconds in the above padInt calls instead of game.Time.
    Hope that helps.

    I took too long to replied and got ninja'd by both of you hehe

    Socks is king :D

    Socks is not just King but also the Queen, lol

  • tintrantintran Posts: 453Member

    @Dell7730 said:
    Socks is not just King but also the Queen, lol

    Are you saying that Socks is female gender?

  • Dell7730Dell7730 Posts: 388Member, PRO

    @tintran said:

    Next question is.... I want the time to be the final score to show who's the fastest. will the strings inside the Display Text be saved to submit in the leaderboards?

  • Dell7730Dell7730 Posts: 388Member, PRO

    @tintran said:

    hahahaha

  • SocksSocks London, UK.Posts: 12,725Member

    @Dell7730 said:
    will the strings inside the Display Text be saved to submit in the leaderboards?

    Saved to what or to where ?

  • Dell7730Dell7730 Posts: 388Member, PRO

    @Socks said:

    as the final score that can be posted to the leaderboards

  • Maybe+i+am+meMaybe i am me Posts: 25Member

    How can i save this timer to show when finish my game :smile:

Sign In or Register to comment.