Trigger multiple timers using a variable tag

0 favourites
  • 7 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi there,

    I have an object that spawns multiple times. For each instance, I need to start a regular timer.

    But every object spawned has a different instance variable containing the time in seconds to start that timer.

    So, I was trying to change the timer tag based on another instance variable, an ID. This way, the tag changes each time, and so does the On Timer tag.

    For example

    Loop spawning objects

    OBJECT Start Timer _ "Name"&Object.InstanceVariableName for Object.InstanceVariableTime seconds (Regular)

    OBJECT On timer "Name"&ObjectInstanceVariableName Actions

    It works for the first set of spawned objects, but every time I change the instance variables to start a new set of objects with different a timer setup, the previous set of timers stops.

    However, if I change the program and create different Timer Tags hardcoded, like:

    Inside the loop

    if "Name"&ObjectInstanceVariableName = Name1 then Start Timer "Name1"

    if "Name"&ObjectInstanceVariableName = Name2 then Start Timer "Name2"

    ...

    On Timer "Name 1" Actions

    The setup works perfectly, and the previous timers don't stop.

    My question is:

    Is there a way to start multiple timers with tags that are variable strings and not "hardcoded" names? How do I do that?

    (I have also tried to use a string global variable that was set before the Start Timer and was set to be the timer's tag and on timer trigger, but that didn't work as well, I thought it could be a "string problem" or something)

    Thanks.

    Tagged:

  • but every time I change the instance variables to start a new set of objects with different a timer setup, the previous set of timers stops.

    You mean you create a few new instances, start timers for them, but this stops the running timers on previously created instances?

    This should not happen. You are probably not picking the right objects in your loop. Can you post a screenshot of your events, or project file?

    .

    Also, this event will not work:

    OBJECT On timer "Name"&ObjectInstanceVariableName Actions

    "On timer" events need to be hardcoded. Or you need to check them in a "For each" loop on every tick.

  • Hey, this is the current situation:

    (I know I am not stopping the timers right now, I'll deal with that later...)

    With this setup, when I press 1, objects are spawned over my skill icons in position 1. And the cooldown box starts working perfectly.

    When I press 2, the new objects are spawned over the skill icons in position 2 and their timer starts. But the previous boxes (over number 1 icons) stops...

  • How do you know that previous timers stop? Did you check them in Debug Mode?

    I'm guessing the timers keep running, but "On timer" is not triggered for them. If you need to use "On timer" like this, you have to put it into "For each" loop:

    For each Object
    	Object On Timer "Name"&Object.var
    

    This is not a very good usage of the timer, because you need to run this loop on every tick, but it should work.

  • First of all, thank you for helping me :)

    Checking in debug mode I now see that the timer did not stop, you were right. I thought it has stopped because my coolbox stops reducing its height.

    I understand your solution and the downsides of it.

    I'm trying to create that "cooldown" effect over a skill in a RPG, I have multiple skill icons and I want to create that effect in every instance of that skill icon when I activate the skill.

    Do you know a better way to do that? Considering that every skill has its own cooldown time as an instance variable.

    P.S. I'm new in Construct.

    P.S. Sorry about my English if something I wrote is not clear, it's not my first language.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Why do you need different timer names? Can't you run all timers with the same name and check the variable inside the "On timer" event?

    Object On Timer "cooldown"
     For each Object
    	Object.var=1 ... do some actions
    	Else Object.var=2 ... do some other actions
    

    Note, "For each" needs to be inside the "On timer" event in case multiple timers are triggered in one tick.

  • That is probably a good idea, I'll try that as soon as possible to check if it works for my application.

    Thanks again :)

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