Every X seconds independent for same objects

  • Hi,

    I can't work out how to do in events every x seconds to be different for each object of the same type depending on its variable value. So I have variable "Wait" and variable "Time" and I want every "Wait" to add 1 to "Time". Wait has got different value for each object. Please help!

    Miko

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would suggest just using the timer behaviour. timer(name) <= 0, create timer (name, instance variable).

    on timer(name): Add 1 to "time"

    Effectively does what you're after with less room for trouble and more room for additions.

  • Thanks. I was looking for timer tutorials but cant find any. Would happen to know of one?

    togroFswi@TIDE to mention I need it to loop.

  • Hm, no sorry I kinda just learnt it myself. It's simple enough though, if you just read through the expressions.

    Here's a picture which covers 2 different ways to get timers going on each of your units and how they trigger. If you have specific questions fire away :)

    IMAGE

    EDIT: Sorry, I still can't get images to post properly. Just follow the hyperlink.

    EDIT 2: Both methods shown to start the timer loop. They just do it in different ways ('regular' setting automatically loops the timers, but the time comparison method creates a new timer every time the previous one expires).

  • Thanks.

    got this, but it doesn't seam to work at all

    <img src="http://img51.imageshack.us/img51/6491/ewnr.jpg" border="0" />

    EDIT@ I've made a mistake, and left "Once", but changing to regular changed nothing.

  • First problem is that the timer is constantly being created, therefore never counting down ;) Add the condition that checks the timer is at or below 0 or make it an onCreated event with a regular timer.

  • Yeah, I've tried with trigger once while true. but the only one group starts. After moving things around first second group started moving but the movement seams broken. Does timer works per sprite?

  • No you don't want trigger once while true, just copy one of the methods in my image exactly as they are (except with your own timer and object names of course).

    They both work perfectly for me. The 'on timer' works per sprite, but the creation doesn't, hence the need to use a for each loop or onCreated (which does occur for each one in case you weren't aware).

    If you want, send a capx and I'll fix it for you.

  • Ok thanks. I'll give it a shot, and if im still stuck i will send the capx.

    Ps. This drives me nuts for few days already ><''

  • Yeah cool :) And I know your pain, I went through it just after timers were released and I was defiant to use them, for no reasonable reason. I created ways to do it, but all were harder without the added extras, so I strongly suggest you get comfortable with them to just make life that little bit easier.

    Also something you might find relevant one day: every X seconds counts from start-up and not from start of layout. I once had two different layouts that ran scripted scenes and they both worked perfect alone. But when I tried to make one lead into the other, the timing was all messed up. I spent a damn long time trying to figure that one out! xD

    EDIT: Actually I should add that timer behaviour is great for small things like this, but if you want a comprehensive timer system that allows pausing, dt adjustments and conditional count-downs etc., you still need a well evented system. I spent a long time refining separate, co-functioning timer systems for my RPG. The biggest hassle I came across was no way to reference the dt of an array, but that's a whole other story ^^

    Another thing to remember is that the timer behaviour will count down using the dt of the instance using the behaviour. This can be a blessing or a curse, so remember it if you ever have the need to play with dt!

  • So if my variable WAIT is 4 which suppose to resemble 4 sec, it's not gonna be 4 secs in the timer, right?

    EDIT@ We might be in the same boat, as what I'm doing is a sequential movement for objects, like spikes, so they do things one by one within the group.

  • Uff, man, Thanks so much for your help. I've made it!

    I don't even know why it's working, but somehow it is! >.> Hopefuly it wont cause much lag when quite a few of those will be on screen. Now got to expand on it.

    <img src="http://img19.imageshack.us/img19/833/quz7.jpg" border="0" />

    Edit@ BTW, can I pull it of with families? As it stand, both container and spikes are in the same family.

  • Cool! Glad to see you got it :) Why this one works and the other didn't, is that you put 'on start of layout' condition above the 'for each'. So it only triggers once, instead of every tick. The thing to look out for here though is that any objects created after the start of the layout will not have their timers activated (which is why I prefer to use one of my other methods).

    And yep, definitely works with families. And there should be no noticeable effect on performance, I have have 100+ objects with timers going and saw no impact, unlike my evented timers which did cause some drain.

  • Thanks buddy,

    I've already go whole level spawning system programmed and already did add the timer there. Here is just to see if its working. ;)

    My game is a shooter so that's why I'm bit worried. A lot of enemies on screen.

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