Spooky problem! Objects dont exist but exist...?

0 favourites
From the Asset Store
Spooky forest background scenes for Spooky Places endless runner mobile game.
  • This is an issue (that was not there a couple of days ago) and I still can't figure out what is causing this. I figured out that a level from my game was messed up and after 2 days of investigation I found the specific line where the issue occurs.

    I am creating some 9 objects that belong on a certain family. Then I want to adjust some properties of those objects. The issue is that while the creation of the objects occurs, when I try to use "for each" the debuggers skips the line.

    I have placed a browser alert to count the objects while they get created and after the creation ends. In the creation process the alert goes normal:

    1,2,3,4,5,6,7,8,9

    On the next line the alert shows "0" !!!!

    What is even more crazy, is the fact that the objects still exist. I can see them on my game, I can see them on the debugger, but Construct cant access them...

    Here is the screenshots from the code and when I use debugging

    How is this even possible? This layout was working just fine. Its a part of a whole game and I had to open this layout for about a month now. A few days ago I have realized that it doesnt work anymore!

    Any ideas, or suggestion?

  • Objects are actually created at the end of the tick. (EDIT: apparently not)

    When you use "Create" action, you can access this instance in the same event (or sub-events). But other events don't know about this newly created instance yet. You can add "Wait 0" at the beginning of event #49, which means to wait until the end of the tick, and then your alert will show the correct number of instances.

  • Objects are actually created at the end of the tick.

    Not quite, objects are created directly with the action. However, they are not available to be filtered/picked until the next top-level event. The "Pick by unique ID" condition is the exception to this rule, it can be used to pick any object, even if it was just created within the same event stack.

    That said, I still don't understand why the "count" expression is acting so weird, and I can't seem to be able to reproduce said behavior.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [del]

  • Newly created objects becomes available at the next top-level event, not at the next tick.

    I tried recreating the problem but the count expression in my case always returns the expected value. I must be missing something I can't see from those screenshots.

  • You are right.. I never noticed that other top-level events can "see" newly created instances.

  • This has been a long standing quirk (due to the complexity of updating data structures actively being used while running events), but Construct tries to paper over the gap in a few places. 'Pick by unique ID' can always pick newly created instances even if they haven't reached the end of the top-level event yet, and IIRC the count expression also takes in to account newly created instances, but most other features don't take them in to account until the next top-level event.

  • This is not the issue. First of all I want to say that this thing didn't happen some days ago. This was working fine and after working on other things on other things on other layouts, I found that this by accident. I was working on another layout that was my main menu that also suddenly stopped working (all positions got messed up and I tried to recreated by by scratch).

    For some reason the even "for each" gets skipped. The second time it passes this group "for each" is working by this is not how it is supposed to work. I can see all objects on the debug mode and there is nothing that can force Construct to pick those objects. I tried to put wait 0 seconds, I broke it into 2 different functions (1 creating tokens and the other accessing tokens to change private variable). I broke it into different groups... nothing!

    This is not happening anywhere else on my projects, not even on other projects. I cant even reproduce this. Its like something is messing my projects and I cant't figure out what this is.

    a) Tokens get created

    b) tokens cant be accessed, Construct skips this loop whatever I try.

    Of course I also tried different picks, putting tokens inside different families, removed from families, renamed tokens, renamed families... and nothing!

  • You definitely don't need "Pick all" in event 17. Try removing this condition (leave it empty) and add some browser log message to event 17, above the loop. Will it show up in console log?

    There must be an explanation, but it's hard to speculate without seeing your project. Maybe the whole group gets deactivated by some other event (like "Token on created"). Can you reproduce this issue in a small project and share it?

  • I had the same without "pick all". The group only gets deactivated by one line at the end of this group. I have put a log message and it works. But with browser alert "tokens.count" I only get "0". I cant reproduce it because it doesn't happened on the rest of the project. This is extremely frustrating and awkward bug...

  • I can take a look at your project if you don't want to share it here, maybe I'll see something that you missed. My email is doperst2006 (at) gmail.com

  • Spooky becomes more spooky....

    After putting an alert to show "token.count" and after a "wait 1.0 second" (because without this, the count is 0 although its on another event + event level) I have noticed this:

    If I put a single alert, it shows "9" (which is correct as I have 9 tokens created)

    If I put 2 alerts, the first one shows 0 and the second one shows 9!

    If I put N alerts, then guess what? It shows 0 until the last which shows 9!!!

    Its like the count of the objects only takes place on the last alert. Even if you put another condition or even wait in between, then the tokens.count only works for the last event.

    I am starting to believe that there is a completely messy code under the hood regarding instance picking/counting etc. Which obviously is more than frustrating because this is a game engine. Game engine supposed to have 1 thing super clear and solid.... object access...!

  • I can take a look at your project if you don't want to share it here, maybe I'll see something that you missed. My email is doperst2006 (at) gmail.com

    I have sent you the project sample. You can find those event on "playStage" event sheet

  • I think you forgot the attachment.. If you resend it, I'll check it tomorrow, it's the middle of the night here where I live.

  • If no instances of an object are picked then all it’s expressions default to 0.

    What should happen is in event 48 the just created instance is picked. Then in 49 all the instances should be pickable like normal. But looks like none of the token instances are picked in 49, hence getting the zero.

    Looks like a bug. If the event were not in a group then 49 would have all the token instances picked. Groups shouldn’t affect that.

    At one point events in groups were considered sub-events. There was then a change so they would all be top level events so new object picking would work. If that’s no longer the case it appears to be a bug.

    EDIT:

    Got around to testing this. Can't reproduce. The token.count or things not being able to be picked.

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