Why won't "trigger once" fire in this specific case?

0 favourites
  • 14 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • The last "Trigger once" line doesn't fire at all in this case:

    While in this case it does:

    I just can't figure out the logic behind this. "Trigger once" should logically always fire once on the first tick within an event which condition is true, so why do I need to move it to the top for it to work?

    What's stranger is that the root condition still fires, so I could for example do this:

    But as soon as I move the "Console.Text"-action down into the "Trigger once" event, it just won't fire.

    Anyone know why this is? Because I just can't figure it out.

    EDIT:

    Just to be clear, the end-goal here isn't to print the text, it's to figure out why "Trigger once" isn't firing in this case.

  • "Trigger once" needs to be the last condition in the event. Don't put it in the sub-event.

  • "Trigger once" needs to be the last condition in the event. Don't put it in the sub-event.

    Having no other conditions in the event automatically makes it true. It's not true that "Trigger once" can't be used as a sub-event. It can be used on any level.

  • Yes, I know it can be used this way. I meant - does it work when you move "trigger once" to the parent event?

    Edit: I tried the same code and couldn't reproduce this issue. "Trigger once" does fire in the sub-event.

  • Yes, I know it can be used this way. I meant - does it work when you move "trigger once" to the parent event?

    No. The root event stops firing if "Trigger once" is added to it. However, if I move the root event to the top, as I illustrated in my original post, then it works.

    So, these all work:

    And these don't fire at all:

    EDIT:

    There seem to be some major glitch with the forum software that's preventing my attached images from showing up. I've uploaded 6 images to this post, so hopefully they'll be visible to everyone. For me they're only showing on and off.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've actually had the same struggles. I agree that it should work how you're expecting but I can't tell you why it doesn't.

  • Can you share your demo project? I tried the same code and it works fine for me.

  • Can you share your demo project? I tried the same code and it works fine for me.

    Sure: quackgyver.com/junk/v0001.c3p

  • Funny enough, the problem is with the Console object. You are destroying one instance of Console and creating another in the same tick. So I'm guessing the text "You're connected to the internet." goes into the deleted instance.

    Don't destroy Console on start of the layout and you'll see that everything works correctly.

  • Funny enough, the problem is with the Console object. You are destroying one instance of Console and creating another in the same tick. So I'm guessing the text "You're connected to the internet." goes into the deleted instance.

    Don't destroy Console on start of the layout and you'll see that everything works correctly.

    Wow, you seem to be correct.

    I'm confused though. Shouldn't a deleted object be completely cleaned up before moving on to the next line? It doesn't make any sense to me that a deleted instance would somehow remain until the end of the loop, and be able to cause bugs throughout the entire loop.

  • Actually, there are no instances of Console object at the moment that event is triggered. The first instance is already destroyed, and the second is not yet created.

    I still don't fully understand when the newly created instance becomes available for subsequent events.. It supposed to be accessible in the next top-level event, but it's not always the case.

  • Actually, there are no instances of Console object at the moment that event is triggered. The first instance is already destroyed, and the second is not yet created.

    I still don't fully understand when the newly created instance becomes available for subsequent events.. It supposed to be accessible in the next top-level event, but it's not always the case.

    That's so strange to me. I'd expect a destroyed object to be completely cleared before moving on to the next line, and I'd expect a created object to be fully available before moving on to the next line.

    I hope that the Construct team can jump in and provide some answers.

  • This is another case of the "newly created instances are not fully available until the next top-level event" quirk.

    If you create an object, you can use it in the same event and sub-events, but not in sibling events, until the next top-level event. Since those events are all in a group, the newly created object is not available in subsequent events, until the end of the group (which is the "next top-level event" point).

    The reason for this is to make the event engine fast, it assumes the internal data structures do not change while running events. Creating an instance changes the internal data structures, but this change is delayed until the next top-level event when it is safe to update the internal data structures, because it's not half-way through running events. We could remove the limitation by slowing down the entire event engine for everyone (i.e. adding regular checks for "did the internal data structures change" through the entire event engine). But that makes all Construct games slower just to solve this quirk, so it doesn't seem a reasonable thing to do. And if we break the assumption that internal data structures do not change, it ends up with crash bugs - and user reports of exactly those crashes is what led to the current "wait until next top-level event" workaround. So the quirk lives on.

  • This is another case of the "newly created instances are not fully available until the next top-level event" quirk.

    If you create an object, you can use it in the same event and sub-events, but not in sibling events, until the next top-level event. Since those events are all in a group, the newly created object is not available in subsequent events, until the end of the group (which is the "next top-level event" point).

    The reason for this is to make the event engine fast, it assumes the internal data structures do not change while running events. Creating an instance changes the internal data structures, but this change is delayed until the next top-level event when it is safe to update the internal data structures, because it's not half-way through running events. We could remove the limitation by slowing down the entire event engine for everyone (i.e. adding regular checks for "did the internal data structures change" through the entire event engine). But that makes all Construct games slower just to solve this quirk, so it doesn't seem a reasonable thing to do. And if we break the assumption that internal data structures do not change, it ends up with crash bugs - and user reports of exactly those crashes is what led to the current "wait until next top-level event" workaround. So the quirk lives on.

    Ah, thanks for the clarification. That explains things.

    Is there anywhere where I can read more about how the event engine processes things, and especially in regards to quirks that might be good to keep in mind? I feel like I frequently run into problems like these.

    Also, thanks to everyone who took the time to help figure this out. Thank you.

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