Are timers still inconsistent, or could I be doing something else wrong?

Using a timer, I am spawning an instance of an actor once every second.

In this actor is a timer set to increase a self attribute by 1 every 0.1 seconds.

This actor begins moving as soon as it enters the scene. When it collides with another (stationary) actor, I display the value of that self attribute.

Sometimes that self attribute has a value of 7 at this collision, and sometimes a value of 8. The speed at which it is moving never changes. This value should never change.

If it's still an accepted fact that timers are a little inconsistent, I suppose I can just accept that and achieve the desired effect another way. If they are NOT inconsistent anymore, I will have to dig deeper to figure out what's going on.

What's the consensus on timers nowadays?

Thanks!

Comments

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

    So if I understand correctly, two instances of an actor are moving at a set rate from the same location towards a stationary actor and they are triggering their collisions at 0.1 seconds apart from each other? I would think that would be possible depending on when each actor is firing its collision rule...

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

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited June 2017

    @Adrenaline

    timers are a bit inaccurate at such short intervals.

    Timing rules are sometimes more precise. Use the following:

    Rule: If game.Time >= self.TimeStamp +0.1
             Spawn something
             self.TimeStamp = game.Time
    End Rule
    

    The following illustrates timing fluctuations under certain conditions:

    These are ticks dropped (spawned) in place from a moving actor.

    • The first row are ticks dropped with the above timing rule (nice and steady).
    • The second row shows ticks dropped by a normal timer behavior.
    • The last row are ticks spaced according to the actual time taken from one normal timer cycle to another.

    In my experience the timer behavior is much more susceptible to other happenings in your game, than timing rules.

    That said, your difference in results is also likely a result of rounding problems, due to when the game detects the collision.

  • MelodyCatsMelodyCats Member, PRO Posts: 128

    I'm not sure how or why (or maybe I'm imagining something) but ever since custom collision shapes were introduced in creator 1.24, I've had constant issues with timers. Really hope cc shapes might be reviewed by GS team when they go back to working on the engine.

  • AdrenalineAdrenaline Member Posts: 523

    @Hopscotch said:
    @Adrenaline

    timers are a bit inaccurate at such short intervals.

    Timing rules are sometimes more precise. Use the following:

    Rule: If game.Time >= self.TimeStamp +0.1
             Spawn something
             self.TimeStamp = game.Time
    End Rule
    

    The following illustrates timing fluctuations under certain conditions:

    These are ticks dropped (spawned) in place from a moving actor.

    • The first row are ticks dropped with the above timing rule (nice and steady).
    • The second row shows ticks dropped by a normal timer behavior.
    • The last row are ticks spaced according to the actual time taken from one normal timer cycle to another.

    In my experience the timer behavior is much more susceptible to other happenings in your game, than timing rules.

    That said, your difference in results is also likely a result of rounding problems, due to when the game detects the collision.

    Thank you @Hopscotch , that pretty much says it all.

  • AdrenalineAdrenaline Member Posts: 523

    @tatiang said:
    So if I understand correctly, two instances of an actor are moving at a set rate from the same location towards a stationary actor and they are triggering their collisions at 0.1 seconds apart from each other? I would think that would be possible depending on when each actor is firing its collision rule...

    Apologies for the confusing explanation. You've got it mostly right. I'll try to explain again, just for clarity's sake.

    Spawn actor A at the center of the screen. It moves with a set speed towards a stationary actor B. In actor A is a timer that increases a self attribute by 1 every 0.1 seconds. When A and B collide, I change a rule that stops the self attribute from increasing, and I display that self attribute. It shows a value of 7.

    I do all of the above again, and sometimes it shows a value of 7, sometimes a value of 8. The locations, distances, speeds, rules are all identical in both cases. Therefore, I began to question the accuracy of the timer.

Sign In or Register to comment.