timer not respecting different instances

Get help using Construct 2

Post » Tue Jun 09, 2015 1:23 am

Hey there everyone.
This is the code I currently have.

Image

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????
Image
B
22
S
5
G
2
Posts: 65
Reputation: 1,724

Post » Tue Jun 09, 2015 7:16 am

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 told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Jun 09, 2015 1:10 pm

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.
Image

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.
Image
B
22
S
5
G
2
Posts: 65
Reputation: 1,724

Post » Tue Jun 09, 2015 2:50 pm

Image

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.
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Tue Jun 09, 2015 7:13 pm

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.

Image

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??
Image
B
22
S
5
G
2
Posts: 65
Reputation: 1,724

Post » Tue Jun 09, 2015 8:00 pm

Did you look at the CAPX I included? It works fine. The 'trigger once after 10 seconds' is nonsense.
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Tue Jun 09, 2015 8:01 pm

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
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Jun 09, 2015 8:46 pm

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.
Image
B
22
S
5
G
2
Posts: 65
Reputation: 1,724


Return to How do I....?

Who is online

Users browsing this forum: WilliamJames and 5 guests