On destroyed > a tricky condition to use?

  • Hi everyone!

    So, I'm chasing a bug for 2 days, and now I just found the guilty event.

    So I'm not asking for help, just to understand :)

    After a few layout restarts, objects were disappearing randomly. No crash, just like a "limit" or a leak happened, and bam, random objects were messed up.

    In the (so great!)debbuger:

    * 3 or 4 layout restart: 750 objects.

    * after that: 500, 200, THEN, negative values in the debugger, like -1000 objects, then -12000 etc...

    So, here is why my game went crazy.

    Now I know I made a mistake here, but I don't understand what was wrong with this.

    <img src="http://tof.canardpc.com/view/5d502514-22b9-4642-843a-f94fcd3a22a0.jpg" border="0" />

    If my block is destroyed, then it generates 2 particles.

    Why so much side effects? Is it dangerous to use the "on destroyed" condition?

    Thanks for yout time.

  • It is always safer to do stuff before the object is destroyed just in case it gets destroyed first.. also avoid calling things on your object once it is destroyed. Obj_blocks has been destroyed but you are then calling to actions on that object. It might be safer to do something like set a varaiable called "Destroyed" on the object. Set the variable to true, then have an event that when Destroyed is True do those other actions and destroy obj_blocks...

    Just a thought, it is always tricky trying to call actions on an object that is already destroyed...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 'On destroyed' gets called for each object when the layout changes or restarts. You don't want to be spawning new objects when the layout is changing so you could use a variable like this:

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/spawnOnDestroy.PNG" border="0" />

  • Now I understand!

    Pretty clear it was not a good idea, then.

    Will do your way, thank you both for the explanation :)

    ( As the destroy event is more "safe" in other game making tools, maybe it could deserve a small warning im the C2 Gui or at least in the documentation, for newcomers )

  • Aurel

    If you're able to make the object count negative then I'd most certainly say it's a bug that should be fixed. I can't find a way to reproduce it, but if you can make a minimal capx or make your capx as minimal as possible and report it to the bugs forums that would be good.

    While BluePhaze's advise is true in many programming languages, for C2 it's not. It's designed to make it completely safe to still access objects directly after they are destroyed and once they are completely destroyed you can no longer access them.

    @ramones

    That seems to be some odd behavior there, so I filed a bug. I would expect no object to survive a layout change unless it were global, regardless what event it were created from.

  • R0J0hound I reported that before and Ashley said he wouldn't fix it. http://www.scirra.com/forum/r116-changing-layout-and-on-destroyed_topic62431_post383279.html

    This guy had the disappearing objects and negative object count problem as well: http://www.scirra.com/forum/helo-im-a-train-wreck_topic76244_post456666.html?KW=debugger#456666 I wasn't able to recreate it in a new capx but it seems to be related to spawning particles in 'on destroyed'.

  • Sounds like I'm not totally crazy :)

    For the capx submition, I would be happy to do it, but my game is pretty heavy, and sources are full of this weird language called french.

    It'll be quite some work.

    I'm ok to translate everything in plain English, and try to reduce the game to a minimum, but if Ashley already said he doesn't consider this as a bug but more as a bad condition usage, maybe it's useless?

    I'm ok with that being not a real bug, but it really could get a text warning saying to not spawn particles with it :)

  • R0J0hound

    I just saw your bug report with a capx included. You were fast on this one!

    Thanks to you, hopefully it can be fixed!

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