Easy question on how best to track actor count...

Hey all, i've got a pretty easy question for you (i think).
I need to accurately keep track of how many of my actors are on screen, because when they're all gone (hit zero) a new wave of actors need to spawn. I've been able to achieve this by having an attribute that is updated with a +1 everytime an actor spawns. So when the attribute hits zero it then sends the new wave out. However, while this works 99% of the time, i've noticed sometimes it doesn't.
Is there any better way of doing this that can guarantee stronger and more reliable results? Thanks!

Comments

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    That's how I've done it in the past without any issues. Are you sure all of your actors are adding the +1? Sounds like one might be doing something different if it's not working 100% of the time.
  • RPRP Member Posts: 1,990
    edited March 2013
    I had a spawn counter going on rescue bacon. I recognize that sometimes it works sometimes it does not. How does it behave on the ad hoc? Do you have run to completion on? (on relevant behaviors).
  • gamesfuagamesfua Member Posts: 723
    Thanks @rp and @jamie_c yeah i have run to completion on. I've run it on ad hoc too. It seems like the issue happens if a few actors are destroyed at the exact same time.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    The Change Attribute behavior that increases or decreases the count should be in the individual actors that spawn, not in the spawner actor.

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

  • gamesfuagamesfua Member Posts: 723
    Thanks @tatiang but you lost me there. Can you explain what you mean? Are you saying that the spawned actor should not have any change attribute, BUT actors outside of it should?
    Meaning lets say your actor is spawned and then it overlaps something that destroys it- that the object destroyer should have the change attribute versus the spawned actor changing the attribute?
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    I would put the spawn count increment behavior before the Spawn Actor behavior and the decrement behavior right before the destroy actor behavior. Order of behaviors matters.
  • gamesfuagamesfua Member Posts: 723
    @codemonkey i'm pretty sure i've done that, but i've been wrong many times before ;) haha
    So thanks! Definitely going to check that out. I'm sure you're right. Thanks again everyone!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @anatomy of dreams, the way I always set it up is this:

    Spawner actor
    Spawn actor [actor name]

    Spawned actor:
    Change Attribute game.actorCount to game.actorCount+1
    When [condition for destroying the actor]
    .....Change Attribute game.actorCount to game.actorCount-1
    .....Destroy Actor

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

Sign In or Register to comment.