How does Call Function timing work?

0 favourites
  • 5 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • 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?

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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:

  • Thanks, that clears things up a bit.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)