Most likely a comprehension issue with sub-event and blank sub-event.

0 favourites
  • 4 posts
From the Asset Store
An educational game for Fill in the Blanks. An easy to use template for developers to build larger games
  • I place instances of a power plant on a map. I collate some of their instance variables (power output) to know how much power is being produced in total.

    This does not work as expected with the attached version. What happens here is that the newly placed instance is not recognized. object.count/ is zero after placing the first object instance. After I place the second object it's 1 then 2 and so on... SO alway one behind.

    I get the proper result when I use a dedicated debug event which I start with a button.

    I suspect this issue is based on me using event and sub-event wrong or an async operation Create object that I need to wait for.

    I have attached the C3P file in case somebody wants to take a look.

    The offending code is on event sheet 51_Area in group Widgets Place Remove and function e_grid_update.

    I have .logged and debugged the hell out of this thing so any pointers would be appreciated.

    https://drive.google.com/file/d/1qyxwkb2nFV8Nnhl9xjJ60OlyVD524qcH/view?usp=drive_link

  • Adding Wait for previous actions to complete after every Create and Destroy fixes the issue.

    Can someone confirm that Create and Destroy are asynchronous actions? I did not expect that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Can someone confirm that Create and Destroy are asynchronous actions? I did not expect that.

    No, they are not. "Wait for previous action" in this case works similar to "Wait 0" - it delays the execution until the end of the tick. But I don't recommend using "Wait for previous action" like this, because in some rare cases it may actually wait for some other async action to finish.

    The problem with Create and Destroy actions is that they are not performed instantly. Until the end of the event or end of the tick object counters may not be updated, and other events (or functions you call) may not be aware of the created or destroyed instances.

    There are a few ways to work around it:

    1. Add "Wait 0" after Create action. This will delay until the end of the tick, so use with caution as it may break the logic.

    2. Pick newly created instance by UID or using "System Pick Last Created" condition.

    3. Use the next top-level event to update the counters.

  • Very helpful, thanks!

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