Randomly spawning enemies after they're destroyed?

Mikee

  • Posts: 5
Hey everyone,

I'm pretty new to Stencyl but I've used the RPG Maker engines for quite a while so I'm pretty used to the event system Stencyl uses.  However; I'm having some trouble trying to get this to work. 

Here's what I'm attempting:  My game revolves around defeating enemies.  Surprising, right?  But I'd like them to respawn on the map as long as the Enemy_Max attribute hasn't been reached... essentially, spawn x amount of enemies and respawn up to y amount every z seconds. 

I attached a picture of my code snippet.  It seems pretty logical to me, but when enemies are destroyed they aren't replaced, and if I place my enemy max higher than the enemy quantity I get a black screen and have to force close flash.

Any help would be appreciated.  If you need more info, let me know.


Kajitii

  • Posts: 184
Never ever use a loop that cannot terminate using the code in the loop.  Loops will run to completion before anything else happens.  That will solve your freezing problem.

Mikee

  • Posts: 5
EDIT:  Yeah...  I think I got it fixed for the most part.  No more freezing.  However;  now for some reason I can only get the enemies to respawn at higher numbers.  Not that it's that big of a deal because there shouldn't ever be less than 5 or 6 on a map at a time, but still, it would be nice to figure out why it's not letting my max be anything less than about 5.

EDIT:  It keeps spawning now and won't stop.  I've given up for the night. Ha ha.  Any extra advice would be greatly appreciated.

« Last Edit: June 26, 2012, 11:38:03 pm by Mikee »

Kajitii

  • Posts: 184
It would help if you posted the whole code in its entirety!  I cannot answer your question with the information currently provided.

SadiQ

  • Posts: 1795
Try with a boolean attribute:

When Created
    Set <mybooleanattribute> [true]
        Do every <Spawn Time> seconds
           If  <mybooleanattribute> = [true]
              Create [Enemie] at x: y:
              Increment [Enemie Quantity] by 1

When Updating
 If [Enemie Quantity] > = [Enemie Max]
   Set <mybooleanattribute> [false]
   
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

Mikee

  • Posts: 5
That is the entire code for the entire behavior, and I'll try that boolean idea and let you know.

Thank you.

EDIT:  Yeah.. the boolean thing just gives me a black screen again.  I even tried rearranging it into 3 events now.  One that spawns the initial spawn count, one that checks the count and sets maxed to true when the count reaches the "enemy max", and a third one that checks the maxed boolean and respawns enemies and sets their count as they're spawned.

I guess I don't get what order the events trigger in, or if "do always" commands are constantly looping or not.  Because it seems like if they're "do always" then they should loops every frame.

Any other info would be great.  Really unsure why this isn't working.

« Last Edit: June 27, 2012, 07:37:17 pm by Mikee »