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
[attachment=1:guc1pdoj][/attachment:guc1pdoj]
[attachment=0:guc1pdoj][/attachment:guc1pdoj]
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