Call function after delay

For questions about using Classic.

Post » Sun Mar 21, 2010 7:35 pm

I have the following code:
(made code italic which is not important for the question)

[code:26g3m46i]on collision between Sprite1 and Box:
[i]- deactivate bullet movement Sprite 1[/i]
- Function1: call function "Function1" after 2000 ms

On function "Function1":
[i]- make text visible[/i]
- add 1 to global variable 'test'[/code:26g3m46i]

Then what happens is: global variable 'test'-counter goes up to 3!
I expected the variable got as result: 1, because there is only 1 collision-event.

Can this be explained?
B
16
S
5
G
7
Posts: 599
Reputation: 5,000

Post » Sun Mar 21, 2010 11:28 pm

Probably some additional small movement causes the event to trigger multiple times since you only have one condition, which is the collision. Add another condition under it like "Is Bullet movement active for Sprite 1". Since you deactivate the bullet movement in the event, it shouldn't trigger again.
B
16
S
8
G
4
Posts: 136
Reputation: 3,144

Post » Mon Mar 22, 2010 1:04 am

Do you have more than one instance of the function object?
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Mon Mar 22, 2010 5:42 am

I tried replicating your results, but I actually got the opposite. Instead of adding 3 for each bullet it added 1 for 1... within the delay, but more than one collision during the delay messes the count. Seems like one is canceling out the other.
Might try the timer behavior instead.
Image Image
B
161
S
48
G
90
Posts: 7,351
Reputation: 66,757

Post » Tue Mar 23, 2010 12:03 pm

Thanks for the replies.
After I tried the wait object (downloaded v0.99.84), I worked around the problem.
B
16
S
5
G
7
Posts: 599
Reputation: 5,000


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests