Is there any way to determine the number of active actors with any given tag?

Just getting started with Gamesalad, so I think I might be missing something, but is there any way to determine the number of active actors with any given tag? This would be used in a situation where a level would restart once the count of actors with a certain tag is zero.

Thanks in advance, Allen

Best Answer

  • ElfizmElfizm Posts: 489
    Accepted Answer
    As mentioned by helpful @tatiang

    In your example that you said, you said that you wanted to know that if all actors are destroyed reset level.

    They way I would do it is have an attribute called game.Howmany ect.

    Then on all the different actors that are involved have a rule that at the start change game.howmany to plus 1.

    That way this a counts for others that have spawned ect. And when they get destroyed change game.Howmany to minus 1.

    That way when game.Howmany is equal to zero restart level.

    I an guessing this may not work properly because it's set to 0 at the start at default so may not be the best method and just needs to be adjusted.

    So if want to do tags have separate attributes and change them accordingly to the actor tag.
    Just another option. But think it's Already been explained so now you cab read it twice.

    Also welcome to forums :)

    Cheers
    Elfizm

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,928
    Unfortunately, no. Actor tags are not available during runtime except as a condition of collision (When actor collides with actor with tag [tag name]).

    You can certainly keep track of the number of a certain actor on the screen, and you can also make your own tags by creating a self.Tag attribute and using index, integer, or text values to label actors.

    For example, you might have the behavior Change Attribute self.Tag (text) to "enemies" at the top of the rule list for all actors that should have that tag and then you could have a rule When self.Tag is "enemies" AND [condition to destroy the enemy]... Change Attribute game.enemiesCount to game.enemiesCount-1 and Destroy [this actor].

    If you explain a bit more about how you intend to use tags with actor counts, I might have other ideas for how to set this up.

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

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,914
    edited December 2012
    I think you could access the tag right from the editor. You can read non adjustable variables at runtime but not change them.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,928
    I think you could access the tag right from the editor. You can read non adjustable variables at runtime but not change them.
    You're right! I just set up a rule When attribute self.Tags is "Enemies"...

    and it worked. No need for a custom attribute after all.

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

  • allenfreeseallenfreese Member Posts: 1
    Thanks for the suggestions... I was doing the tracking manually before, but my logic is a little wonky, so I was hoping there was a brute force method... but since not, I'll need to track down what I am doing wrong. Thanks again.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,928
    I'm not sure what you mean by a brute force method. The easiest way to do this is with two rules:

    When attribute self.Tags contains [tag name]
    .....Change Attribute game.tagCount (index/integer) to game.tagCount+1

    When [condition for destroying the actor]
    .....Change Attribute game.tagCount to game.tagCount-1
    .....Destroy Actor [this actor]

    This will keep an accurate count of the number of actors with that tag on the screen.

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

Sign In or Register to comment.