GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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

Answers

  • tatiangtatiang Posts: 11,796Member, Sous Chef, PRO, Senior Sous-Chef
    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 Posts: 9,913Member
    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 Posts: 11,796Member, Sous Chef, PRO, Senior Sous-Chef

    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 Posts: 1Member
    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 Posts: 11,796Member, Sous Chef, PRO, Senior Sous-Chef
    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

This discussion has been closed.