wait next tick

Discussion and feedback on Construct 2

Post » Mon Mar 25, 2013 12:10 am

Hey there,

I just had this simple idea.
It's ver well know, now that when we have a newly created or destroyed object, we need to wait for the next tick to access them.
For instance when we use functions a lot even when the function is called in the created block, the newly created object won't be visible.

My usual work around is to put a wait 0 seconds

But it's not really intuitive. And at some point, nothing insure that this behavior will be kept in future versions (since it's more like a hack). Maybe in the future, the implementation of wait will be changed and wait 0 seconds will trigger instantly... who knows?... and why should we care about internal implementation? (:

So maybe an action dedicated for just that situation, like a "Wait next tick" OR "trigger next tick" action would be better (although "triger next tick" looks more like a condition)

What do you think @Ashley ? (:
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Mar 25, 2013 12:36 am

Created objects are accessible after the next top-level event - you don't really need to wait a full tick. But I guess the easiest workaround is to wait a tick.

Wait 0 seconds is actually deliberately 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). This is intentional and I won't change it since it will break useful things such as this! So I think it's fine to keep using "Wait 0 seconds" like that.
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Mon Mar 25, 2013 1:11 am

oh , good ! I was lookin' for this one for a long time ... Meaning , no wait 1 tick @Ashley ?
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Mon Mar 25, 2013 1:36 am

@Ashley

Yeah I know about the next top level thingy, but that makes a capx look a bit harder to read when you do that:
[code]on left click
-> create object
on left click
-> function call "checkThings"

on right click on object
-> destroy object
on right click on object // should that trigger by the way?
-> function call "checkThings"[/code]

instead of:
[code]on left click
-> create object
-> next tick
-> function call "checkThings"

on right click on object
-> destroy object
-> next tick
-> function call "checkThings"[/code]
(plus you probably would have to repeat some picking condition/calculation to end up with the same context in more complex situations)


And the idea behind creating an alias to wait 0 seconds, is that it looks less wrong ('cause if I understand, you actually wait more or less dt seconds)Yann2013-03-25 01:38:10
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Mar 25, 2013 7:21 am

I've been thinking about this "top level delayed picking" for some time and I like the idea Yann is proposing. If calling it Pick Created Instances (or similar) it would be clear in the code what's going on: 'I now discard any previous pickings and continue to configure the newly created'
B
7
Posts: 2
Reputation: 530


Return to Construct 2 General

Who is online

Users browsing this forum: tarek2, Yahoo [Bot] and 14 guests