How to use the On Timer condition?

0 favourites
  • 12 posts
From the Asset Store
Tabata timer
$4 USD
60% off
Template for Tabata timer, fully documented in comments and video
  • I'm trying to set up a Timer on an object. Once a Human sprite has is in collision with a Tree sprite, it should start 'collecting' the wood resource every 2 seconds, adding to the Human's wood total variable, and deducting from the Tree's wood remaining variable.

    I have a regular Timer in the 'on collision' event, but when I go to add the 'On Timer' condition in a sub-event, it doesn't show up as an option.

    The blue line is where I want to add the 'On Timer' condition.

    I feel like I'm missing something obvious here. I've seen 'On Timer' referenced hundreds of times online, but I can't find it in my editor. Below is all I see when I select the Human object in Conditions. The object has a Timer behaviour attached.

    Tagged:

  • You can't put triggers as subevents of other triggers

    Right now you're trying to put 'On Timer' under 'On Collision'

    Put 'On Timer' as it's own top-level event, not as a sub-event

    (Even if C3 did let you put 'On Timer' under 'On Collision', your character would probably never gather wood. Your code would make it so your character has to simultaneously collide with the tree RIGHT as his collecting timer goes off)

  • Hi,

    I agree full with Noah, if you're pretty new to the concepts, maybe you can check out some of the video's on my youtube channel, where you can also find some examples where I use timers. A lot of them have some logic involving some kind of timer. For example falling shapes alternative or slot machine.

    youtube.com/channel/UCZ6QjvqEs9dR2miRnfFqIpQ

    Hope that helps in any way

    cheers

  • Put 'On Timer' as it's own top-level event, not as a sub-event

    Ok, I did that but still no joy. This is what I have now:

    There are no other events impacting these two, they could effectively run on their own.

    I'm wondering if because it's not a sub-event of the collision condition, it now doesn't know which tree to deduct from? If so, how would I re-link it?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > Put 'On Timer' as it's own top-level event, not as a sub-event

    Ok, I did that but still no joy. This is what I have now:

    There are no other events impacting these two, they could effectively run on their own.

    I'm wondering if because it's not a sub-event of the collision condition, it now doesn't know which tree to deduct from? If so, how would I re-link it?

    To link the tree and the character you can use UIDs.

    Give the character a variable called TreeUID

    Then, when the character collides with the tree set TreeUID to res_Tree.UID

    When the character's timer goes off use Pick Tree By UID: character.TreeUID to pick the correct tree

    However, I can anticipate there being a different problem if the character's collision box changes during it's animation. It may repeatedly collide with the res_tree as it's frame changes. Try opening the game in debug mode so you can get a better look at what the timer is doing

  • To link the tree and the character you can use UIDs.

    Give the character a variable called TreeUID

    Then, when the character collides with the tree set TreeUID to res_Tree.UID

    When the character's timer goes off use Pick Tree By UID: character.TreeUID to pick the correct tree

    However, I can anticipate there being a possible problem if the character's collision box changes during it's animation. It may repeatedly collide with the res_tree as it's frame changes. Try opening the game in debug mode so you can get a better look at what the timer is doing

    I was about to do that, but I decided to re-check the Debug Preview one last time. It turns out the "gatherResource" timer is being reset every tick, which I didn't notice before (I only just discovered the Watch tool!):

    It tries to go up, but only ever gets to 0.1/0.2 seconds before being reset. There aren't any other interactions with that timer in the Events Sheet, except for the "On Timer" condition below it.

    The parent event to that set-timer-event is just checking if the Human has a variable of job->woodcutter, in case you were wondering. No reason for any clashes.

    Thanks for your help so far!

  • It tries to go up, but only ever gets to 0.1/0.2 seconds before being reset.

    Interestingly, if you leave it for 20-30 seconds it starts working normally... Any ideas?

  • Chances are your animation frames are recolliding with the tree. One of the first tutorials you should have done recommends using a separate helper sprite as your main object/player, and pin the animated sprite to it. That way the collision box is fixed, and you can have any animation you want but without the side effects.

  • I was about to do that, but I decided to re-check the Debug Preview one last time. It turns out the "gatherResource" timer is being reset every tick, which I didn't notice before (I only just discovered the Watch tool!):

    It tries to go up, but only ever gets to 0.1/0.2 seconds before being reset. There aren't any other interactions with that timer in the Events Sheet, except for the "On Timer" condition below it.

    The parent event to that set-timer-event is just checking if the Human has a variable of job->woodcutter, in case you were wondering. No reason for any clashes.

    Thanks for your help so far!

    So If Human's job = woodcutter -- > Set timer?

    If that's really the only parent condition then the timer is going to be constantly restarting, which is going to override itself and never let it complete. Try adding a 'Timer "gatheresource" is NOT running' condition before you set the timer. That'll prevent the timer from being set if it's already running

  • Thanks everyone for your suggestions!

    blackhornet was almost there with collisions. I added a "Turn off collisions" action right after the "on collision with tree" event, and everything worked as normal. I guess it just kept colliding and restarting the timer each tick!

    I then turned them back on once the character had finished collecting wood, so that they can drop it off at the storehouse.

  • Thanks everyone for your suggestions!

    blackhornet was almost there with collisions. I added a "Turn off collisions" action right after the "on collision with tree" event, and everything worked as normal. I guess it just kept colliding and restarting the timer each tick!

    I then turned them back on once the character had finished collecting wood, so that they can drop it off at the storehouse.

    I told you about collisions a few posts ago!

    "However, I can anticipate there being a possible problem if the character's collision box changes during it's animation. It may repeatedly collide with the res_tree as it's frame changes. Try opening the game in debug mode so you can get a better look at what the timer is doing"

    blackhornet is right about the solution as well, it's a good idea to have a sprite that acts as a hitbox and then a skin that you pin to the hitbox. It will make your life a lot easier. Disabling collisions is not a good long term solution. Imagine your character gets attacked while collecting wood. The attack won't collide with your character because collisions are disabled!

  • Sorry , I don't think I fully appreciated what you were suggesting when I read it first time, then got distracted with another issue and forgot by the time I came back to this issue :`D

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