On destroyed > a tricky condition to use?

Get help using Construct 2

Post » Fri Nov 08, 2013 8:47 pm

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.



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.Aurel2013-11-08 20:48:27
Image | @AurelRegard on twitter
B
19
S
6
G
1
Posts: 307
Reputation: 2,500

Post » Fri Nov 08, 2013 11:08 pm

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...
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,583

Post » Fri Nov 08, 2013 11:24 pm

'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:

B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Sat Nov 09, 2013 2:28 am

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 )
Image | @AurelRegard on twitter
B
19
S
6
G
1
Posts: 307
Reputation: 2,500

Post » Sat Nov 09, 2013 7:35 am

@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.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Sat Nov 09, 2013 11:07 am

@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'.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Sat Nov 09, 2013 3:21 pm

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 :)
Image | @AurelRegard on twitter
B
19
S
6
G
1
Posts: 307
Reputation: 2,500

Post » Sat Nov 09, 2013 7:07 pm

@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!
Image | @AurelRegard on twitter
B
19
S
6
G
1
Posts: 307
Reputation: 2,500


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests