Getting and setting an attribute from another actor in a group [Solved]

MoonKing

  • Posts: 7
Ok so this problem has been driving me up the wall. I have two groups: Units and Enemies. The group Units has three actors in it, Swordsman, Spearman, and Bowman.  The Enemies group is going to have more actors in it like Calvary, Buildings, Slimes, and other killable things.  Whenever a unit or enemy actor is created they have a set amount of Health and Attack as an internal attribute.

My problem is getting them to "set" the internal health attribute when ever they collide by subtracting the Attack attribute from the collided Health attribute. I've gotten this to work between multiple Spearman actors and Enemy Slime actors,  but when I try to add other actors into the mix they can only collide and won't exchange attributes.

This is mainly because the get and set attribute block requires a specific event for the getting and setting. I like how I can just go through the menus to click on the actor attribute I want, but I'd like Stencyl to just set the Health attribute for whatever actor it collided with. Is there a way to do this? If there isn't, it would mean I would have to create a get/set block for every actor that actor could ever collide with. I like to avoid this because I'd like to have roughly 20 to 30 enemies in my game. Having 20-30 blocks of "if this actor then" seems frightfully inefficient.

« Last Edit: August 21, 2014, 05:52:17 pm by MoonKing »

Innes

  • *
  • Posts: 1960
It's quite difficult to follow your description, but this sort of thing should be straightforward in Stencyl.


Have you seen the [when actor-type hits actor-type...] or [when actor-group hits actor-group...] blocks?


You can use those to get and set actor values or attributes for the individual actors that collide. You grab the attack value from the enemy involved in the collision and subtract it from the health of the player involved in the collision.


You don't have to write code for each actor type that might collide with another actor type.
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

MoonKing

  • Posts: 7
Not sure I follow. But when I get or set the health, the health attribute will always be from ActorEvent_5. How do I have ActorEvent_5 change to the collided actor?

Meestar

  • Posts: 654
Instead of using "Last Collided Actor" use the (member) of group draggable block from the "When Self hits a (member) of Enemies" - <1st Actor> <(member) of Group>.
PM me if you require help.  I'm always glad to help out!

MoonKing

  • Posts: 7
No that still does not fix it.

When the collision event goes to Get or Set the attribute Health, it references the health of just one Enemy actor. What I want, is for the behavior name to update to the collided actor. I have two actors that are called ActorEvent_5 and Actor Event_25 in the code(when you hit the binoculars). These are two different actors but are part of the same group called enemies. They both have an attribute called Health.

What I'd like is when an Actor from the group Units, collides with one of these Actors from the group Enemies, is to pull the Health attribute from the collided actor and update the attribute.

MoonKing

  • Posts: 7
If it helps here is a picture of what I'm trying to do.  Each black line represents what actors can damage other actors health attribute.

Currently with my code blocks, whenever an actor from the group Units (Spear, Knight, Wizard) hit a Slime (Group: Enemies ActorEvent_5), it destroys the Slime in three hits. But if I try to add another enemy actor into the fray (Goomba ActorEvent_7), the actors collide and bounce off each other but do not register damage. Plus I get an error in my log saying that Behavior ActorEvent_5 does not exist.

Meestar

  • Posts: 654
So, why not create a behavior called "Health Manager" or something and attach it to each of these different actor types and set the health values to the appropriate values?

Slime - has Health Manager - Health = 3
Goomba - has Health Manager - Health = 1
Koopa - has Health Manager - Health = 5
Bower - has Health Manager - Health = 20

You can also use a Health Manager for the Units as well, or modify the one for the enemies to work on both Units and Enemies by checking the groups of the colliders.

When Self Collides with Member of Enemies
   Set Health to Health - Damage for in behavior Health Manager for Actor (Member of Group).

This would be a much easier approach than the one you are attempting.
PM me if you require help.  I'm always glad to help out!

MoonKing

  • Posts: 7
Meestar, Thank you. I think your method solved my problem. Thank you so much!