timer is this by design

Discussion and feedback on Construct 2

Post » Tue Dec 31, 2013 2:21 am

Hi all,

I have a simple project which contains only two instances of sprite object with timer behavior and two text objects, text1 and text2.

https://www.dropbox.com/s/y5vyugjt9po0be6/timer_test.capx

When the layout starts, each of the sprite's timer gets started.
In the "on timer" event, each instance of the sprite object set the text property of a specific text object.

But the second text object's text property is always intact since when the "on timer" event occurs C2 always pick the same instance of the sprite object.

Is this by design?

Thanks for any comment.
B
5
Posts: 6
Reputation: 237

Post » Tue Dec 31, 2013 3:02 am

Since you are using the same tag, and both trigger at the same time, both are picked in On Timer. Add a For Each condition to On Timer, and each Sprite is then evaluated and it works as you expect.
ImageImageImage
B
71
S
22
G
258
Posts: 3,792
Reputation: 143,200

Post » Tue Dec 31, 2013 9:20 am

I see.
But I found even they don't start the timer at the same time, when "on timer" event is triggered, C2 still picks the same instance. You must add your own logic to check whose time is up.

Is't it convenient to have each instance to have its own on timer event like "on destroy" or "on create" which references the instance who triggers the event?

Tag maybe is a solution .But if you have many many instances, you must maintain so many "on timer" event even they all do the sam thing.
B
5
Posts: 6
Reputation: 237

Post » Tue Dec 31, 2013 12:43 pm

It's by design. 'On timer t' fires with both instances picked, because both their timers fired at the same time. Since the event 'i = 0' runs, the 'else' event does not run (else ignores picking of instances). If you replace 'else' with an inverted condition, it works fine.
Scirra Founder
B
403
S
238
G
89
Posts: 24,653
Reputation: 196,143

Post » Wed Jan 01, 2014 4:54 am

Oh, I see, thanks.

Is there any way to tell which instance starts the timer?

https://www.dropbox.com/s/nhx8k8qjeuaak6n/timer_test2.capx

In the project, no matter which instance start the timer (at different time with different tags),when the "on timer" event occurs, all instances get picked.

Does the timer always treat the object's instances as a whole?
B
5
Posts: 6
Reputation: 237

Post » Wed Jan 01, 2014 5:04 am

OK, now I understand I have to start the timer at different time or with different tag.

@ Ashley, Thanks .
B
5
Posts: 6
Reputation: 237


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests