[Solved] Spawning a Specific Actor Only if Amount Below Set Attribute

tristonhopkins

  • Posts: 69
I'm trying to limit the amount of a specific actor that can be on the screen at the same time.  To give an example, I'm working on a game where I have actors continuously spawning every few seconds just offscreen and moving towards the player.  I want to be able to limit the amount of these actors that can be alive at once so that the game does not lag, and because too many of these actors can make the game difficult as well.

I was trying to use an attribute that was increased by one each time of these actors is spawned, and checking that the attribute is less than an attribute that is defined as the maximum amount of allowed actors.

I cannot figure out how to get this to work easily, and I feel like I'm missing something simple.  The behavior I scripted for this is a scene behavior, and the behavior that broadcasts the actor's death is an actor behavior.  I can't seem to get them to hear messages from one another, unless I'm doing something wrong.

« Last Edit: December 22, 2011, 02:23:09 pm by tristonhopkins »

rob1221

  • *
  • Posts: 9424
The actor should be able to talk to the scene by using the "tell this scene to X for X behavior."  When the actor spawns, increase the count by 1.  Just before the actor dies, decrease the count by 1.  If count is over max, stop spawning actors.

tristonhopkins

  • Posts: 69
Thanks!  I didn't quite understand how to use the block you were referring to, but I figured it out and it works perfectly now.

tristonhopkins

  • Posts: 69
I figured out that the reason it wasn't working as I thought it should is because the Enhanced Health Pack by Stencyl's Health Manager doesn't broadcast it's messages to scene behaviors.  Once I told it to also broadcast it's messages to scene behaviors, everything worked using the methods I was originally trying to use.