Making a "speed run" Timer

Hello, I am looking to add a running clock/timer to see how fast players can beat the game. I have not found anything in the forums. I have given a valiant effort BUT in two variations, I have had problems...
1. I set an actor to display attribute:timer decimal.
Within that actor another rule: Every 0.1 seconds... change attribute timer decimal to timer decimal+1.
another rule: When attribute timer decimal >9, change attribute timer decimal to 0
Next I set another actor up like the previous actor BUT with attribute "timer seconds" instead of "timer decimal". and "every 1 second... change attribute timer seconds to 1.

The timers do not line up when displayed together. So i tried this other formula...]
2. after 0.1 seconds...The rule says timer seconds attribute changes when timer decimal =0
This method works great an all the numbers line up... HOWEVER when I take a real life stopwatch and compare it to my game time, the game clock is much slower. Stopwatch said 30 seconds while my game was around 25 seconds...

Does anyone have any ideas on how to make a clock that will keep real time?

Comments

  • bob loblawbob loblaw Member, PRO Posts: 793

    i had honestly never noticed that. cheers for pointing it out.

    i know in unity, the timer properties on various devices will vary slightly so you need to multiply all time variables by a thing called 'time.deltatime'. not sure if gs has something similar you need to use.

    i have been having a play around since reading this though, and it seems like the timer and interpolate functions are out of sync (interpolate seems more accurate).

    you could try using interpolate with a linear setting to count up to a huge amount of seconds, or limit time on a level and display it using the precision function to show to the right decimal places you need.

    so if you had a variable called 'timer', you would use display text and in the expression editor use 'precision(timer,2)' to display to 2dp.

    your interpolate behaviour would be something like interpolate timer to 5000, duration 5000, function = linear.

    to display as min:sec.00 you would need to obviously change the display text expression to break up the display of timer and maybe use the padreal function (eg. floor(timer/60)..":"..padreal(timer,3,2)%60 ). this won't display two seconds digits when the seconds are less than 10 though, so you'd need to also put a rule in saying something like if floor(timer/60) < 10 ...... and in your display text behaviour, add in a bit to display a "0" next to the ":" and before ..padreal.

    hope that my gibber makes sense. if not, let me know and i'll add a basic demo.

  • mikejamesfishermikejamesfisher Member, PRO Posts: 88

    Thanks for looking into it! Yes, a lot of your ideas indeed go over my head. You don't need double talk, you need Bob Loblaw! I don't know what precision and 2dp and padreal are. lol. But don't make a demo. That is too much time for something that may not work for me... I could just forget about connecting it to real time. I don't think anyone(if anyone plays it) will notice or care. (that can be said about a lot of the details i make sure to get just right. I mean, GS games don't have a great track record of downloads and I'm not a strategist in advertising)

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    2dp = two decimal points

    padreal is a math formula. You can search for the term here: http://help.gamesalad.com/gamesalad-cookbook/1-getting-started/1-11-glossary.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • bob loblawbob loblaw Member, PRO Posts: 793
    edited November 2019

    @mikejamesfisher said:
    Thanks for looking into it! Yes, a lot of your ideas indeed go over my head. You don't need double talk, you need Bob Loblaw! I don't know what precision and 2dp and padreal are. lol. But don't make a demo. That is too much time for something that may not work for me... I could just forget about connecting it to real time. I don't think anyone(if anyone plays it) will notice or care. (that can be said about a lot of the details i make sure to get just right. I mean, GS games don't have a great track record of downloads and I'm not a strategist in advertising)

    precision gives you a value rounded to however many decimals. so in my example, if timer had the value of 100.71234567, using (from the drop down menu) precision(timer, 2) would give the variable 'timer' a value of 100.71, which is a bit cleaner if you use the display text behaviour to display 'timer'.

    padreal lets you determine how many columns to display (including the decimal), so padreal (timer,5,2) would let you display up to five character columns and two decimal places, including the decimal point (i think that's right).

    the bit where i used '%60' set the maximum limit of the counting to 60 before the count pulls back to 0.

    floor gives you a rounded number without decimals. so in my example above, floor(timer/60) returns a minute value rounded down to display minutes

    i have attached a crude demo that shows it, with a bit of a clunky display, but it hopefully will help you get your head around the functions.

    you should also take a look at that glossary that @tatiang linked. very useful to help get your head around gs functions.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    Here is an easy timer - -

    Drag a blank actor to the scene. Then inside the actor:

    Make an attribute called BeginTime (type = real)

    Then make two behaviors --

    Display Text: 
       prec((game.Time - self.BeginTim ),2)
    When: touch is pressed:
       Change Attribute:[self.BeginTime]  To:[game.Time]
    
Sign In or Register to comment.