playMaker

Author Topic: Quickly check Bool value of several objects  (Read 1320 times)

RobotGoggles

  • Playmaker Newbie
  • *
  • Posts: 35
Quickly check Bool value of several objects
« on: January 01, 2019, 07:41:09 PM »
I'm working on a game where you control a large army, but most of the actions of the player controlled units are automated. I'm having some trouble with my healer class. How can I scan around the healer unit for friendly units that are wounded, so I can ignore or heal the unit accordingly?

Right now Each unit has a bool value called "Wounded" that's switched on when their health is below maximum. The healer currently checks every friendly unit one at a time (they are stored in an array) and checks their "Wounded" value. It works, but it seems very heavy. This seems like an unruly way to go about it, especially when there is a large army with multiple healers.

Is there a more efficient way of doing this?
When life hands you insomnia, make video games.

Athin

  • Full Member
  • ***
  • Posts: 163
Re: Quickly check Bool value of several objects
« Reply #1 on: January 01, 2019, 09:37:44 PM »
Maybe instead of putting a Bool value, you can just simple add them into another array called Wounded.  The healers simple just need to reference that Array and grab the first one on the list.  Once fully healed, remove them from the list.

That can double over to help with healing priority (if you want/need that too) where some wounded units can jump up to first on the list or be place in the back.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Quickly check Bool value of several objects
« Reply #2 on: January 02, 2019, 06:00:36 AM »
Hi.
Arrays are very light actually.
So i think its fine the way you do it.

Also Athin's way is good.

Performance wise both will be virtually the same.