Timed respawn is spawning more than one actor

PoisonCoyotePoisonCoyote Member Posts: 9
edited May 2012 in Working with GS (Mac)
Here is what I am trying to do. I have 2 of the same actors in my scene. Every 2 seconds, if there are at least 2 of these actors left, I want to spawn another one. I also want each of these actors to be able to die independently if they come into contact with the monster actor.

So here is what I've tried:

I've tried both a self attribute and a game attribute for "actors" to keep track of the total number. Neither seemed to work.

I set up a timer for every 2 seconds
if "actors" is greater than or equal to 2
spawn actor
increase "actors" +1
If collide with "monster"
destroy
decrease "actors" -1

The problem comes with the spawning. It seems to be doing the action for each actor available so it will spawn 2, then 4, then 8 etc as the number of actors increases.

How do I get it to only spawn 1 actor at a time but each actor still be an individual that can live or die? Thanks for any help.

Best Answer

  • tatiangtatiang Posts: 11,949
    Accepted Answer
    @akstudiodevelopment is basically correct. You need an actor (off-screen or self.color.alpha=0) that spawns your actors whenever game.dogCount<=2. Wrap that in an every 2 seconds timer. Have your "dogs" change attribute game.dogCount to game.dogCount+1 (without a rule/condition). Also have them change attribute game.dogCount to game.dogCount-1 just before they are destroyed.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Answers

  • akstudiodevelopmentakstudiodevelopment Member Posts: 93
    Perhaps having an actor (invisible) placed at a point where you would like the new single enemy to respawn. Use a global atribute to keep track of how many are alive. Each time an enemy dies, have a rule that decreases the global attribute. Within the spawner, have a rule saying:

    when "enemy" < "5"
    Spawn
    Change "enemy" to "enemy"+1

    Thus spawning as many new enemies to equal the amount for that scene.

    Hope this helps.

    Kris
  • PoisonCoyotePoisonCoyote Member Posts: 9
    I don't have a limit to the number of actors I need spawned. Here is an easier way to describe what I'm trying to do:

    Imagine a mating simulator. You need at least 2 "dogs" to mate and create a new one. You will then have 3. Then every couple of seconds it checks again to see if 2 dogs are still alive. If there are at least 2 then they mate again creating another dog. There would now be 4 total. I don't want all 4 mating, only 2 at a time to only produce 1 more each time the timer goes off. Each of these dogs also needs to be independent to die if a monster touches one of them.
  • PoisonCoyotePoisonCoyote Member Posts: 9
    Thanks for clarifying it a bit more for me. It worked! Hadn't thought about just using an invisible actor to spawn them. I had been putting everything in the actor itself. Thanks!
Sign In or Register to comment.