Using Tables for Enemies

I am creating a tower defense styled game. I would like to have each individual enemy to have their own healthbar. I want to use the same actor sprite instead of having to create multiple actors each with their own healthbar. I think this can be done by using the tables system.

I created a table to experiment with and added 2 rows and 2 columns. The first column is an integar set at 1 and will be my temporary healthbar. The second column is text, labelled one and two.

I also created a global attribute called Monsters as an integer with a value of zero.

I then created an ingame object and set it to spawn two actors in random positions on the map changing the tables 2nd columns values to "Monster1" and :"Monster2". It would also change the global attribute "Monsters" to 2.

Then, on my monster actor, I added an text attribute labelled "zero". From here I planned to add a rule that, when the 1st row and second column contains "Monster1" and the global attribute is 2, to change its text attribute to Monster1. There would be an "else" statement saying that if 1st row second column contains "Monster2" and global attribute is 1 to change its text attribute to Monster2. Then when they get hit by a projectile thrown by the hero Monster1 would change the 1st column table value to zero and if its hit again it would destroy. The second monster would do the same.

Im not sure if I explained this correctly its rather complicated, however if there is a way to do something like this or something even simpler please let me know.

I wasnt able to find a way for the Monster actor to check the values of the table using the "if _Attribute_" condition. And there dont seem to be any other conditions that let me start an "if" statement.

Comments

  • indoorpersonindoorperson Member Posts: 2
    Edit: Seems that its impossible to multiple copies of the same actor with their own individual healthbars in GS. I had a look at DeepBlueStudies template for a TD game and even they didnt have individual healthbars in the game.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Um, it's far from impossible. It's just a pain because you have to constrain a bar actor with its own unique ID that matches the ID of the enemy. Fortunately, tables make this a lot easier than in the past (pre-tables).

    I should have a demo in a bit for you.

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    It's constrain-heavy for sure, but it works!

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Oh my memory... I had already done this back in November. lol...

    In case it's helpful, here it is slightly different (tap the enemies to injure them):

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

  • indoorpersonindoorperson Member Posts: 2
    Thanks! This is much more better and efficient than having multiple actors of the same type! Only problem is that, though it does work on mac, the windows version is still missing the "create attribute as index" option.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Integers can be substituted for index attributes.

    I think the only problem is that if you open a Mac Creator project file in Windows Creator, every index attribute is blank where the name of the attribute would be.

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

Sign In or Register to comment.