Wait 0

Discussion and feedback on Construct 2

Post » Tue Apr 09, 2013 5:16 pm

Hello,
I was reading some tutorials and find the advanced tips and tricks from @Whiteclaws

After the read, I learned something ugly of my point of vision, as a non programmer and a common user of C2.

[quote]Wait 0 Seconds
Wait 0 seconds is designed to postpone until the end of the current run of events (not even the next tick - the same tick, but after all other events).

Explanation :

Condition 1
.. Event1
.. Event2

In this case , event 1 & event 2 will occur in the same tick

Condition 1
.. Event1
.. Wait 0 seconds
.. Event2

Putting a 0 seconds will insure that Event2 will only occur after Event1 is finished

Some examples ...

On start of layout
.. Create Object1
.. Set Variable1 to 0

Here , the two events occur in the same tick , meaning the object is created in the same moment as the variable is changed , The object isn't ready , so the variable is assigned before the object is created ... Doesn't work .

If you place "Wait 0 seconds" between the two , C2 will spawn the instance , wait until it is ready , and then assign the variable

This trick is very useful when you need to call a function then call another depending on the result of the last one ...[/quote]
https://www.scirra.com/tutorials/510/advanced-tips-and-tricks-that-construct2-offers

I always believed C2 did the actions in sequence, without the necessity of waiting 0, also, I never saw a code using the wait 0 before, but if it's true, all my job will need to be redone, without the mention of my pupils =\

@Ashley , do you can clarify if it's really necessary or just a "best practice" or C2 already do the actions in sequence?

That's annoying create an object on the canvas, like an enemy, where you want setup his sine behavior to meet the route you wanted, and all this event run at same time, what could be a mess and/or miss the sine configuration to that specific object and/or shuffle it with another object spawned on the same event.

Thank you for any advice!TELLES08082013-04-09 18:43:47
ImageImageImageImageImageImage
B
93
S
19
G
12
Posts: 1,209
Reputation: 18,367

Post » Tue Apr 09, 2013 6:39 pm

never used "Wait 0 Seconds"
and never had any issues with

On start of layout
.. Create Object1
.. Set Variable1 to 0

so not really sure what's this tutorial is reffering to.
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Tue Apr 09, 2013 7:03 pm

EDIT: My post was completely wrong lolJase002013-04-09 23:01:10
B
45
S
19
G
10
Posts: 562
Reputation: 9,543

Post » Tue Apr 09, 2013 7:23 pm

@Jase00: You can set instance variables on creation of the object without having to use "wait".

It might be possible that accessing the value in another event but in the same tick as the creation might request to wait for at least one more tick (though I think Ash changed this and it actually isn't true anymore).

But in your and @whiteclaws' examples that "wait 0" trick doesn't make any kind of sense to me. (Or maybe whiteclaws' example is badly formulated, since under a condition I'd expect Action1/Wait/Action2, perhaps this needs reformulating as the wait action would have to happen in a blank event)Kyatric2013-04-09 19:24:03
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Tue Apr 09, 2013 7:35 pm

@Kyatric, excellent job on the university!

I'm thinking about it and never occur something strange on creating and setting up an action where two or more objects are created and configured.

But, it need a re-test with two objects of the same type (Example: two bullets) with different configuration from each other (example, an spaceship shooting two bullets, but one go 90 and the next one go 270).

So, the code could be (and was what I would make):
Condition
On touch screen

Actions > Create bullet on layer "Game";
> Set bullet angle of motion to 90;
> Create bullet on layer "Game";
> Set bullet angle of motion to 270;

Later I say what happened...
ImageImageImageImageImageImage
B
93
S
19
G
12
Posts: 1,209
Reputation: 18,367

Post » Tue Apr 09, 2013 7:36 pm

It's really ugly too as a programmer to wait a given time to ensure that an object is created before using it's properties or assigning values. If i had to do this, I would rely on events that are called after the creation of an object.

However, like @Kyatric said, it just works without using wait and I really dont see why it wouldn't.
B
12
S
3
G
4
Posts: 63
Reputation: 3,410

Post » Tue Apr 09, 2013 8:30 pm

@Kyatric , could you suggest me an example , I'm fixing it now ...

So the issue was fixed by Ashley ? My bad , sorry everyone ...Whiteclaws2013-04-09 20:35:44
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Tue Apr 09, 2013 8:49 pm

Everyone is getting confused over nothing. Objects are 100% created immediately and you can access every part of them immediately. There is rarely any need to use "Wait 0 seconds", and most projects will never use it.

I think the quoted text was referring to the fact of a different quirk about creating objects. You can't pick a newly created object in another condition until the end of the next top-level event. Again that's not a problem for most projects, but in rare cases 'Wait 0 seconds' can be useful to help work around that.

Edit: re-reading the quoted text, it's wrong. Assigning variables immediately after creating an object always works, and has always worked, there's never even been any bugs with that (IIRC).Ashley2013-04-09 20:51:13
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Tue Apr 09, 2013 9:04 pm

@Ashley , I'm sorry , I misurstood a text of yours , could you please correct it ?
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Tue Apr 09, 2013 10:04 pm

Fixed ... Sorry everyone ...
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 18 guests