How do I make sure function X is done before calling function Y?

0 favourites
  • 10 posts
  • title.


  • If there are no "Waits" in function X, then the function Y will not start until function X is finished.

    If there are waits or async actions in X, you can set it as Asynchronous and use: Call Function X -> Wait for previous action to complete -> Call Function Y.

  • Function X:

    Create 1000 objects

    Function Y:

    If object count is less than 1000. -Wait 1 second. -Call Function Y

    Else Destroy all objects

    By calling Function Y inside of Function Y it gives you a loop that you can easily control. You have to be careful though that you don't create an endless loop. You can check this by adding a global variable and each time Function Y runs it can add 1 to the variable. This allows you to check in debugger how many times Function Y runs. When you confirm Function Y is acting how it should then delete the global variable. dop2000's would be more efficient though, but I think it has to do with how the logic is set up. I never messed with asynchronous yet.


    The wait in Function Y was just to reduce how many times Function Y is called while waiting for Function X to complete. It isn't needed unless you just want a very small performance increase.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Unconnected If you are creating new objects in function X and want to access them in function Y, you don't need to wait the entire second and call the function recursively. Simple "Wait 0" will do:

    Call Function X
    Wait 0
    Call Function Y
  • dop2000

    If that is the case then I am at a loss.

    Function X creates objects. I want function Y to check if any of them overlap each other, if so, change position. Then repeat function Y until there's no more overlap. But nothing I try works.

    Do you have any suggestion on how to achieve this?

  • I will edit my post to be clear. The wait was to reduce how many times function Y was called while waiting for function X to finish.

  • mutajon In this case I would do something like this:

    Call Function CreateObjects
    Wait 0
     Object is overlapping Object 
    ..........Call Function RearrangeObjects

    Note, "While" should be a sub-event below "Wait 0"

    "Loopindex<1000" condition is recommended to prevent creating an infinite loop.


    Also, see this example:

  • dop2000

    Thanks a lot!

    Will check this out.

  • dop2000

    Umm... How do I create the 'loopIndex<1000' part within construct?

    Can't seem to find this condition..

    Thanks again.

  • Use "System Compare two values" condition.

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