How do I set individual timers for objects in a family?

0 favourites
  • 6 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hi,

    I have 3 objects that belong to a family. I have multiple instances of each of those three groups on the layout.

    I have added a timer behaviour to the family.

    I want to set a timer on each object, and a function to fire when that timer finishes.

    I can easily do it so that all objects act in unison i.e. one timer ends and they all execute function simultaneously. But what I want is for them to be out of sync. I want to set a timer on EACH individual object to timerLength+random(timerLength), or similar.

    How do I code it in C3 so that each object acts as an individual, and they don't keep getting messages from every objects timer - which I think is what is happening?

  • If you start Timer for the entire family for random(n) seconds, it should work exactly as you described - each instance will get its own random timer.

    It's still possible that On Timer event will be triggered in the same tick for two or more instances, so you can add "For each family" to the "On Timer" event if you want to process each instance separately.

  • Ah, I didn't know about the 'for each family' bit. I'll try it and see how it works.

  • I'm still getting the effect where if one timer goes off, it acts on all instances.

    This is what I have that's relevant:


    + Keyboard: On Space pressed

    -> objects: Start Timer "shakeReset" for random(5) (Once)

    + objects: On Timer "shakeReset"

    + System: For each objects

    -> Functions: Call resetShake

    * On function 'resetShake'

    -> objects: Set shakeAmount to shakeStrength

    -> objects: Set shakeTimeElapsed to 0


    The exact function is the objects shake a little to give some animation/game feel. But I want them to shake at random intervals individually, and not be in sync. I can happily get them to shake altogether, but not independently.

    I'd like each instance's timer to make just that same instance shake a little. At the moment the timer of any instance will make ALL of them shake.

    What have I missed in your answer? Thanks for your continuing help!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I've found a solution involving adding the UID to the timer name, and passing the UID into the function:

    + Keyboard: On Space pressed

    -> objects: Start Timer "shakeReset_"&objects.UID for random(5) (Once)

    * On function 'resetShake'

    * Parameter 'objectUID' (Number)

    ----+ objects: Pick instance with UID objectUID

    -----> objects: Set shakeAmount to shakeStrength

    -----> objects: Set shakeTimeElapsed to 0

    + objects: On Timer "shakeReset_"&objects.UID

    -> Functions: Call resetShake (objectUID: objects.​UID)

    Hope that helps someone!

    Now, all the instances work independently of each other, and only listen to their own timer (I think...).

  • Yeah, the problem was not with the Timer. If you want a function to process a specific object instance, you need to pick that instance inside the function. So passing object UID in function parameter was the right solution.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)