Timed respawn is spawning more than one actor

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.
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
-
tatiang Posts: 11,949
@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
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
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.