[SOLVED kind of] Spawning actor by itself

Almakos

  • Posts: 632
Hey guys,
another question from me.
I have bomb which on explode creates actor (called "new explosion"). Now I want to make that explosion trigger bombs like chain reaction, so I am checking whether explosion collided with bomb and if yes, I recycle bomb and spawn explosion, but my game freezes dead, so I should force quit it when explosion hits bomb.
Can you please advise what I am doing wrong?
Thanks

« Last Edit: June 16, 2012, 08:54:20 am by Almakos »
Fishing Fantasy Trailer


rob1221

  • *
  • Posts: 9472
My guess is that the explosion collides with the actor that creates it, causing an infinite loop and crashing the Flash player.  If so, one solution is to change the animation for the first actor to one without a collision shape just before creating the explosion.

Almakos

  • Posts: 632
Thank you Rob, I've tried to do as you suggested, but....
well,...at least I tried =)

When I hit first bomb by explosion it detonates as expected, just once.
Second bomb activates twice
Third - 4 times
Fifth - 8 times
and so on.

heh, I really don't understand what's going on, even though behaviors are not that complicated at this point

I've attached screenshots of behaviors:
1st - when bomb hits anything and explodes after some time
2nd is when explosion hits enemy and destroys it as well as when explosion hits other bomb and detonates it
Fishing Fantasy Trailer


shotfrost

  • Posts: 221
well,i really wonder.if your first picture is stick to the 'enemy bullet'actor,then when the actor hit the explosion,it also create an explosion.and at the same time,behavior from picture 2 also happen and create an explosion.so you have 2 explosion on the second one.and the third bomb hit 2 explosions,so it will creat 2 explosions.and 2 explosions hit the third bomb swell,so it will create another 2 explosions,...so you will have your explosion double each time.however,it is just my guess,because actually i don't know how your game works.

Almakos

  • Posts: 632
Excuse me being dumb, but wouldn't it be like that if I had all 4 bombs exploding one after another in a single chain?

Because in my case  I can drop bomb actor on explosion actor and let them explode for the first time (I read only 1 cycle of explosions for the first pair):
Code: [Select]
    collision disabled
    bomb hit with explosion
    collisions disabled after explosion
    KABOOM
    collisions disabled

When during same game session I drop another bomb on explosion, I will read 2 cycles of explosions:
Code: [Select]
    collision disabled
    bomb hit with explosion
    collisions disabled after explosion
    bomb hit with explosion
    collisions disabled after explosion
    KABOOM
    KABOOM
    collisions disabled

Then after some time when all explosions finished I drop third bomb and I will get 4 cycles:
Code: [Select]
    collision disabled
    bomb hit with explosion
    collisions disabled after explosion
    bomb hit with explosion
    collisions disabled after explosion
    bomb hit with explosion
    collisions disabled after explosion
    bomb hit with explosion
    collisions disabled after explosion
    KABOOM
    KABOOM
    KABOOM
    KABOOM
    collisions disabled

I don't understand how can this number grow each time...It is like I have some invisible counter or something is not get reseted within actors behavior when recycled.

This is crazy )))
Fishing Fantasy Trailer


shotfrost

  • Posts: 221
well,why don't you try kill the actor and create a new actor instead of recycle it?the result could be different.actually,that is the only thing that i think is the cause of the problem.just try a shot.if it does not work,i think you should check your whole game.sometimes,the error comes from many behaviors that seems unrelated.i have been in this situation a few times already.

Almakos

  • Posts: 632
Ok, with killing instead of recycling it works perfectly...so I guess I will avoid using recycled actors (for now), because I simply don't understand how they work.

Huge thanks to you shotfrost. I would be hitting this wall for much longer time without your advice.
Fishing Fantasy Trailer


froz

  • Posts: 250
Block "if actor is alive" literally means if he is alive. If he is recycled, not killed, then he is alive (just hidden). There should be a block "if actor is not recycled" to use for recycled actors. Actually I believe you can do that in code and it shouldn't be too hard, but as I never coded anything, I'm in no position to tell how exactly to do that.

Almakos

  • Posts: 632
...shouldn't be too hard, but as I never coded anything...
unfortunately me neither. I hope someone who understands how this should work can provide us with code like that officially
I actually have no basic knowledge about when and how to use usual or recycled actors. I thought recycled are cheaper, so decided to use them everywhere I could =) apparently I was wrong
Fishing Fantasy Trailer


froz

  • Posts: 250
Well, in theory recycled actors should make the game perform better, at least when you are creating many of them (like bullets). However in my game I checked it and didn't see any performance difference and I have to know if an actor is killed, so I just used normal actors. Also I've seen some people saying strange things happen with recycled actors and I'm not sure if they are fully reliable.