How do I add wait functionality inside a function?

Get help using Construct 2

Post » Tue Aug 04, 2015 8:54 am

Hi,

I need to add a function in which I need to add "wait for 2 seconds". But when I call the function, the wait is ignored. Is this a bug or am i missing anything?

you can see my function here http://snag.gy/S91uW.jpg

Thank you,
B
9
S
2
Posts: 59
Reputation: 763

Post » Tue Aug 04, 2015 9:06 am

its working fine on me r210

you can try to put the wait event and the actions under it to an empty sub event inside the function
Image
B
28
S
11
G
2
Posts: 139
Reputation: 3,299

Post » Tue Aug 04, 2015 9:54 am

actually it works when there is just a call to one function. Suppose if there are 2 functions continuously, The second function runs async mode,

Is that normal?
B
9
S
2
Posts: 59
Reputation: 763

Post » Tue Aug 04, 2015 1:07 pm

The Wait x seconds command does not stop all execution of code. It only affects the lines immediately after it.

So, the last two lines of the function "onCollision" will happen after the wait, but the rest of your game code will continue to run every tick (1/60 of a second). That means if you call "RestartFunction" right after calling "onCollision" then that will happen in the SAME tick.

Another thing to be careful of is that after the wait time is up, when those last two lines do execute, the function will no longer have the same objects picked. In your case you may only have one explosion object, so it would probably be ok. But if your function is meant to do something to one enemy, then lines after a wait command would apply to all enemies unless you re-pick the one you want.

You could move calling the RestartFunction inside the onCollision function (after the Wait line). Or have a Game Over message pop up, and have the user decide when to restart while the explosion is still running in the background...
B
97
S
34
G
20
Posts: 438
Reputation: 17,790

Post » Tue Aug 04, 2015 1:11 pm

Thanks @AllanR Yes, I am moving the restartfunction to onCollision.

Thanks for explaination and points. I will remember these,
B
9
S
2
Posts: 59
Reputation: 763


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, khelaghor and 40 guests