How does Call Function timing work?

Just started using Construct 2? Post your questions here

Post » Fri Mar 18, 2016 5:45 pm

Sorry if this question is confusing, I'm very confused as well.

Here's the capx, it's probably better at explaining itself than I will be:
https://www.dropbox.com/s/6xjmj13x95048 ... .capx?dl=0

At the start of the layout, I make a red square spawn a blue square, and have Red store Blue's UID, while Blue also store's Red's UID.
I have two functions. They both do exactly the same thing: they accept the UID of a red square as Param(0) and pick the blue square it spawned. The only difference is in how they pick the blue square: either
- by using Blue's Pick by UID action and using the value stored in Red, or
- by using Pick By Compare and comparing Blue's stored Red UID value to Red's actual UID.

The latter method doesn't work. But it only doesn't work if I do as I said above and have Red spawn Blue and store values at that point. If I actually just have Blue on the layout, don't spawn anything, and still have them store each other's values on Start of Layout, the latter method works perfectly fine. It also works if I call the latter function by clicking on Red.

The only conceivable reason I can think of is that on the start of layout, the Pick By Compare function runs before Blue has a chance to store Red's UID, and thus when the function tries to Pick By Compare, Blue's stored value is still 0. Is this actually the case?
B
20
S
5
Posts: 23
Reputation: 1,283

Post » Fri Mar 18, 2016 6:41 pm

This has to do with picking a newly created object. This has been discussed many times. Pick isn't guaranteed to work until the next top-level event. So in this example, if you make a second "On start of layout" and move the two function calls there, it will work.
ImageImageImage
B
71
S
21
G
220
Posts: 3,648
Reputation: 123,725

Post » Fri Mar 18, 2016 7:10 pm

Thanks for the response. I did as you said and it does indeed work with another On start of layout event.

Do you have any suggestions to how I can get around this when spawning a new red square, and using its 'On created' event instead of 'On start of layout'? Using another On created after it isn't working, and I don't know of another way to simulate the same solution.

Edit: Scratch that, I had the wrong function being called. Having another On Created works as well. Thank you.
B
20
S
5
Posts: 23
Reputation: 1,283

Post » Fri Mar 18, 2016 9:02 pm

It has to do when a newly created object is pickable. You can find details about this with a search about toplevel events.

This link has info about that:
viewtopic.php?f=147&t=152869&p=964496&hilit=toplevel#p964496
B
91
S
31
G
102
Posts: 5,233
Reputation: 67,252

Post » Fri Mar 18, 2016 11:14 pm

Thanks, that clears things up a bit.
B
20
S
5
Posts: 23
Reputation: 1,283


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests