0 Favourites

Objects immediately disappearing.

  • I've been having the usual problem of not being able to use objects which have just been created which are on the same 'level' as the next groups of code. As such, I've had to move the function to create my objects to a higher level, so that the next group of code is in the level lower. But now the strangest thing is happening.....

    I create my objects in a function (which is at an even higher level and I can confirm that the objects are created) but in the very next line of code, when I do an object.count, it's back to zero.

    I've always had this problem with C2 and the solution is usually to check that the objects are created on a higher level, but it seems to have changed.

    So it's like this.

    -------> Call Function to create objects

    Object count is zero.

    --> Function to create objects (top level).

    Object count is 10 when leaving function.

  • Can you upload the capx so we can check what you're doing wrong?

  • Unfortunately not because it's huge and won't work without the access to my database. I've had no choice but to make the objects permanent from the start of the game instead of creating them just for a certain screen (and then deleting them later). It's working now, but I'm not sure what was causing that problem before.

  • Sprite.Count will return 0 if there are no existing Sprites. You can't call an expression (.Count) on a Sprite object if there aren't any Sprite objects. It would be like using Sprite.X or Sprite.Width when no Sprites exist. It would just return 0.

    So after the function call where the objects don't exist yet, then there is no object to call object.count on. But if you had at least 1 object already on the layout then it would work.

  • But surely if the function creates the sprites, then immediately after returning from the function, sprite.count should show 10 (I made 10). Or is your point that the objects don't actually 'exist' at that point? If so, when do they begin to exist?

    I should say that I'm happy with having these as permanent objects anyway really, I can just keep them offscreen when they're not needed. But it'd still be interesting to know what happened.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • The sprites aren't properly created until the event that calls the function finishes. The sprite count IS updated immediately... but you can't access sprite.count if no sprite exists.

  • So even in a sub-event they won't be accessible? I need to wait till the entire event finishes? This keeps tripping me up with C2.

  • I had this same problem when using the save \ load features. Objects would exist but would disappear after a load and just act strange. Can you attribute the disappearances with occurring after a "load" Switching to Webstorage fixed it for me.

    I didn't do a bug report either due to project size.

    Good luck.

  • I'm fairly sure in my case it was because I was trying to use them in the same event after creating them from a function. Although they still wouldn't work in sub-events. But when I set up the same structure in a few project, it did work, so something must've been wrong with my code somewhere.

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