Trigger events not triggering properly (such as Timer)

Bugs will be moved here once resolved.

Post » Wed Apr 23, 2014 2:11 pm

Problem Description
After starting timers with the same name/tag for several instances, when more than one should trigger at the same time, only the first instance is picked (and the timer event triggers only once).

A workaround is to have a "foreach" as a "super-event" (also works as a sub-event) around the timer trigger events.

This is curious, because if you try to put other trigger events such as "On created" or "On flash ended" inside a "foreach", it will pop up a javascript error at runtime saying that is not allowed;
But if you do it with events such as "On timer" or "On collision with object", then not only does this not yield any javascript error, but it also produces the expected behaviour (i.e. triggers an event for each instance that it was supposed to).

In my humble opinion, it seems to me that some trigger events are not working as trigger events at all, but rather as standard (i.e. "picking instances") events.
Also, no answer was found here:
scirra.com/manual/75/how-events-work
Nor here:
scirra.com/tutorials/292/guide-to-construct-2s-advanced-event-features

PS: A similar issue seems to occur with the "On collision with object" event, in the sense that if some object collides with two other objects at the same time, only one event is triggered. For most of the cases, that would not be a problem, since the instances are picked and the actions run for all of them, but in my case, I was calling a Function and passing the UID of the collided object as an argument, which results in only applying the Function to the first one. A "foreach" also resolved this problem.

Attach a Capx
Timer bug.capx

Timer bug workaround.capx


Description of Capx
Press each "1" button to trigger a "TimerOne" for it; Press "All" button to trigger a "TimerAll" for each.
When "All" is pressed, you can see that the timer is set for all the "1" instances, but only triggers once, for the first one.
When you press "1" buttons, a timer triggers correctly for each one, even when you press several very quickly.

In the "Timer bug workaround.capx" the bug is corrected by having a "foreach" before the timer trigger events.

Steps to Reproduce Bug
  • Start a timer with the same tag and the same duration for more than one instance of the same type;

Observed Result
Timer event only triggers once for some instance.

Expected Result
Several timer events should trigger, one for each instance for which the timer has been started.

Affected Browsers
  • Chrome: YES
  • FireFox: YES
  • Internet Explorer: YES

Operating System and Service Pack
Windows 7 Service Pack 1

Construct 2 Version ID
163
You do not have the required permissions to view the files attached to this post.
Last edited by gaps on Wed Apr 23, 2014 3:13 pm, edited 1 time in total.
B
8
S
2
Posts: 5
Reputation: 587

Post » Wed Apr 23, 2014 2:55 pm

In the mean time, I suggest that you add &Self.UID (eg "timer"&Self.UID) at the end of the timer name and that you check that the timer "timer"&Self.UID is over (I agree that it should be corrected)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Wed Apr 23, 2014 3:03 pm

Aphrodite wrote:In the mean time, I suggest that you add &Self.UID (eg "timer"&Self.UID) at the end of the timer name and that you check that the timer "timer"&Self.UID is over (I agree that it should be corrected)

Wow that's a nice hack, thanks for sharing! :D
I had some questions about how to "pass parameters" to a timer in its tag, but I gave up as I would have to know the parameter value to use it as a tag (I ended up using instance variables instead) - But now you showed me a way to do it, I guess!
But I'll stick with my "foreach" workaround for now, as I think it is cleanner (don't know if it lacks in efficiency though), and that it also solves the issue for the "On collided with object" event (by the way, I've updated the problem description).
B
8
S
2
Posts: 5
Reputation: 587

Post » Thu Apr 24, 2014 12:38 pm

This is actually by design; as you say "On timer" triggers with all the instances that have fired at the same time picked at once, and adding 'for each' is the correct workaround.
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,694

Post » Fri Apr 25, 2014 4:27 pm

Ok then, it is just not that intuitive... Maybe the documentation should mention that?
Still, it's strange that some trigger events can be put inside foreach loops and others don't.
Thanks for the insight!
B
8
S
2
Posts: 5
Reputation: 587

Post » Sun Jun 29, 2014 10:07 am

It also confused me, since the "On timer" has a green arrow. I would suppose that it will pick instance automatically.
B
108
S
26
G
267
Posts: 4,456
Reputation: 149,747

Post » Tue Dec 06, 2016 12:11 am

I know this is an old thread, but I think this event should be per instance. It is not intuitive to have to put a for loop in some events and not in others.

That said, is there any place in the documentation where you mention these kind of events? I'm finding myself adding for loops inside the events when something is not working as expected. That's how I found this problem with timers.
B
15
S
4
Posts: 28
Reputation: 931


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 2 guests