What's a better way to get attributes from actors in the scene? [Solved]

Omniso

  • Posts: 169
I have an enemy in my game that supports and heals other nearby enemies who are  fighting the player. In order to "heal" a completely separate actor in the first place, it needs to know what kind of actor it is to then get its HP. In order to know when to stop healing an actor and move on, it needs to know what that actor's max HP is and if it no longer needs healing. Using what's available, I manually find the ActorEvents names of all enemies, then have the healer select a random target, and then check it against EVERY enemy type in the game along with their hard-coded ActorEvents name just to get its type, so that the healer can then get the correct _HP and _MaxHP attributes. The code for that is shown below, and it's going to get extremely long as more enemies are added.

This only applies to a single target, and now I need this healer to compare the current HPs of all enemies in the scene and prioritize healing the most damaged one. I don't know how to easily do that based on what stencyl gives me. Is there a better way to approach problems like these?

 

« Last Edit: March 17, 2019, 07:51:28 pm by Omniso »

Luyren

  • *
  • Posts: 1665
Create a behavior that holds a non-hidden text attribute. This will be the Identifier Friend or Foe (IFF for short). Attach it to all your actors (enemies and players).

For your support unit, loop through all actors on screen if it doesn't have a target, and for each actor, check for the IFF of the actor. If both IFFs match (your support unit's and the actor in the loop), that means both actors are allies. You can then add all allies into a list, and afterward loop through that list and find the lowest health among the actors in the list, and set your target to that actor. When the health is full, clear the target actor and call that function again.
Working.

Omniso

  • Posts: 169
Part of that is done already, but rather than check a non-hidden text attribute,  this support unit uses actor groups instead to identify friends and foes, since all enemies share a single group. The support unit already loops through all enemies on screen and adds them to a list if they aren't already in it (removing them from the list if they die or move too far away). The problem for me is looping through that list of actors to find the lowest health among them. How do you get and compare attributes from actors referred to only from a list, without knowing the random ActorEvents ID?

Luyren

  • *
  • Posts: 1665
Set a number attribute to a high enough number (don't know the health scaling of your game, so 999999 should cover everything). Start the loop (with the "repeat # of times loop"), and if the current health of the actor is smaller than the number, set the number to that HP value, and set another number attribute (call it "index") to the current loop count. At the end of it, "index" will point to the actor with the lowest HP. The image shows you are getting both current and max HP, so if you want the lowest percentage, just calculate that before hand and get that instead.

Also, to solve that "if" statement cascade you have... why not have a health behavior, and attach it to all your actors that require health? Actor/Scene events ideally would be used for stuff unique to that actor or scene. Health is a universal concept that is used in several actors, and should be a behavior, for ease of use.
Working.

Omniso

  • Posts: 169
THANK YOU! Problem solved. As for why HP isn't in some universal behavior, HP is indeed a universal thing that is shared by all of my actors, but there are too many variables that affect it that are all specific to each individual actor. With complex damage calculations that vary on each enemy, and enemies with unique abilities that further affect how HP is treated are in play, I eventually caved in to the idea of actors having their own local attributes for HP. That way I can handle these unique situations from the very actor that they belong to, rather than doing it all from a single behavior.

If I did have a single behavior where all these situations are handled, I could easily see it being at least 1,000+ lines long.

« Last Edit: March 16, 2019, 08:12:02 pm by Omniso »

Luyren

  • *
  • Posts: 1665
THANK YOU! Problem solved. As for why HP isn't in some universal behavior, HP is indeed a universal thing that is shared by all of my actors, but there are too many variables that affect it that are all specific to each individual actor. With complex damage calculations that vary on each enemy, and enemies with unique abilities that further affect how HP is treated are in play, I eventually caved in to the idea of actors having their own local attributes for HP. That way I can handle these unique situations from the very actor that they belong to, rather than doing it all from a single behavior.

If I did have a single behavior where all these situations are handled, I could easily see it being at least 1,000+ lines long.

Glad the problem is solved. And if you want to talk a bit more about how you are handling your actor's health and such, I can try to give you ways to achieve that with a single behavior (or with a few behaviors that you customize for each actor). Really, lists/maps and some text parsing can do a whole lot for that, might be a learning experience at the very least. Your call either way.
Working.

Omniso

  • Posts: 169
Sure, I messaged you the details.

Edit: Doesn't appear that it went through, I'll send it again.

« Last Edit: March 17, 2019, 11:53:54 am by Omniso »