Nice smooth timer

I_AM_BENJII_AM_BENJI USAMember Posts: 40
edited January 2015 in Working with GS (Mac)

I have been having trouble make a time counter. I want some thing that goes up by .01. I tried use a timer and an attribute saying every .01 seconds add .01 to attribute, but when i do this there are a bunch of other random numbers after as well. Like so 4.45999999 Does anyone no any other methods.

Comments

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

    I believe the fastest timer would be every 0.03 seconds but regardless of that, you can use the roundTo() function to round a number to a certain number of digits. So roundTo(4.45999999,2) would give you 4.46.

    This behavior:

    Results in these log values:

    Log(Actor: Actor 1): 0.02
    Log(Actor: Actor 1): 0.05
    Log(Actor: Actor 1): 0.08
    Log(Actor: Actor 1): 0.12
    Log(Actor: Actor 1): 0.15
    Log(Actor: Actor 1): 0.18
    Log(Actor: Actor 1): 0.22
    Log(Actor: Actor 1): 0.25
    Log(Actor: Actor 1): 0.28
    ...

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

  • I_AM_BENJII_AM_BENJI USAMember Posts: 40

    @tatiang‌ but where exactly do i put the log statement in??

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2015

    @I_AM_BENJI said:
    I have been having trouble make a time counter. I want some thing that goes up by .01. I tried use a timer and an attribute saying every .01 seconds add .01 to attribute, but when i do this there are a bunch of other random numbers after as well. Like so 4.45999999 Does anyone no any other methods.

    Use:

    roundTo(Game.time,2)

    EDIT: whoops, didn't read tatiang's post, basically what tatiang said.

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

    @I_AM_BENJI said:
    tatiang‌ but where exactly do i put the log statement in??

    You don't need to put it anywhere ! In the above example it is just used to show how the formula works.

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

    @I_AM_BENJI said:
    tatiang‌ but where exactly do i put the log statement in??

    You don't need a Log Debugging Statement. That's just for debugging purposes. You would replace that statement with whatever behaviors/rules you want to run every timer cycle.

    Edit: actually, you'd need a custom timer if you want to make sure the timer is running on a rounded number. But... what is the purpose of your 0.01 timer? Are you displaying it on the scene? If so, use the roundTo() function like I mentioned.

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

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2015

    @tatiang said:
    I believe the fastest timer would be every 0.03 seconds but regardless of that, you can use the roundTo() function to round a number to a certain number of digits. So roundTo(4.45999999,2) would give you 4.46.

    This behavior:

    If he is making a game timer he won't need the timer behaviour, or any attributes, he can just display (or track in a rule) your roundTo(Game.time,2) formula.

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

    Lol, true... no need for a timer. Anyway, I guess we need more details...

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

  • I_AM_BENJII_AM_BENJI USAMember Posts: 40

    @tatiang‌ @Socks‌

    Thank you guys
    I guess i am just a noob at this. So yes I am displaying the time through an actor. So anything??? How would i display the time?

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

    Just put roundTo(game.Time,2) in a Display Text behavior. Be sure to select game.Time from the attribute browser in the expression editor. Don't just type it in.

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

  • LovejoyLovejoy Member Posts: 2,078

    @tatiang said:
    Just put roundTo(game.Time,2) in a Display Text behavior. Be sure to select game.Time from the attribute browser in the expression editor. Don't just type it in.

    game.time keeps running even after pausing scenes and such, its best to display self.time with an actor that is there when he wants the timer to start.

    Fortuna Infortuna Forti Una

  • I_AM_BENJII_AM_BENJI USAMember Posts: 40
    edited January 2015

    @tatiang‌
    i got that but now it looks glichy because it is centered and changes from something like 3.47 to 3.5

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

    @I_AM_BENJI said:
    tatiang‌
    i got that but now it looks glichy because it is centered and changes from something like 3.47 to 3.5

    Then don't have it centred ?

  • I_AM_BENJII_AM_BENJI USAMember Posts: 40

    @Socks said:
    Then don't have it centred ?

    Oh i totally new that (not)

    THANKS

  • I_AM_BENJII_AM_BENJI USAMember Posts: 40
    edited January 2015

    @Lovejoy said:
    game.time keeps running even after pausing scenes and such, its best to display self.time with an actor that is there when he wants the timer to start.

    he was talking about my attribute

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

    @I_AM_BENJI said:
    Oh i totally new that (not)

    :smile:

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

    You could use padReal() to force the display of two decimal points:

    padReal(game.Time,1,2)

    It will still "jump" when the integer value (in front of the decimal point) changes length but that's not as often or abrupt as with decimals.

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

Sign In or Register to comment.