timer not respecting different instances

0 favourites
  • 8 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • Hey there everyone.

    This is the code I currently have.

    what i expect to happen:

    1 - "enemy01" is idle, creates a random value for each "enemy01" instance, waits 3 seconds and than starts moving again.

    2 - When "enemy01" starts moving again a timer starts ticking for each instance with the random value from step 1 as the duration.

    3 - When the timer reaches its duration, it would activate making that "enemy01" instance go back to idle, restarting the process for that "enemy01" instance.

    3b - The other "enemy01" instances would continue counting the timer until each reached its duration, restarting the process for each one of them.

    BUT what happens is:

    1 - "enemy01" is idle, creates a random value for each "enemy01" instance, waits 3 seconds and than starts moving again.

    2 - When "enemy01" starts moving again a timer starts ticking for each instance with the random value from step 1 as the duration.

    3 - When the FIRST timer (the one with the lowest duration) reaches its duration, it activates ALL timers (even though the timer on each "enemy01" instance has a different tag based on the instances UID). The "enemy01" instance that had the lowest duration goes back to step 1. All the other "enemy01" instances just go straight to step 2 starting the timer again, but not going back to idle and creating a new random value.

    Ideas????

  • Like you said..

    You want to do this for each enemy..

    adding a for each enemy top-event with event 1 and 2 of your screenshot as subevents should do the trick..

  • I tried using for each as the top event with events 1 and 2 from the first posts image as sub events, but it didnt help.

    This is the closest i got to something working.

    But still. After running the first sequence of events (idle>random>moving>startTimer>onTimer>idle)

    some of the enemies will just stay idle forever, others will create a new timer on the second sequence of events but than just stay idle forever at the end of that. And some will even just stay moving forever, never going back to the idle state.

    soooooo lost.

  • http://blackhornettechnologies.com/Cons ... imers.capx

    Rather than mixing mechanisms, just use the state machine to progress the state. You don't need independent timer tags. I'm using Bullet here since I don't know your movement mechanism.

  • Doesn't work. With the state = idle event the timer keeps starting every tick. so the timer never gets to 3.

    If i place a trigger once on the first event, it runs but after going back to idle for the first time it stays stuck there.

    Im really not sure but it seems like I REALLY REALLY REALLY didnt understand how Timers and Trigger Once work. They always give mixed results when I use them in my project.

    I fixed everything going for something completely different.

    You can see that trigger once is disabled on the last event. If I enable it, it breaks the code at some point.

    **I read somewhere that trigger once only works after 10 seconds of being used, is that correct??

  • Did you look at the CAPX I included? It works fine. The 'trigger once after 10 seconds' is nonsense.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I gues this one does what you intend to do:

    https://dl.dropboxusercontent.com/u/485 ... ouble.capx

    BTW blackhornet capx works, because of setting the state to waiting, it does not have the issues of repeating the action everytime

  • sorry about that. it does work! i probably deleted the "set state to wiaitng" when trying to ctrl+drag it to another event.

    anyway, any good reads on "trigger once"? (other than the obvious tutrials in the site) cause im getting lots of unexpected results when using it.

    specifically when the code comes back to the "trigger once" event again and again. it seems that after the event runs 1-2-3 times it just stops working.

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