(code screenshot attached at bottom)
I have 4 lines of code, each contains a FOR EACH regarding the same family - can it be made more efficient /faster, or would it be OK as is? There is also an odd bug or something in there too.
What it does, is it creates a target on each enemy on screen, when a button is held down, and kills all the targets when the button is released.
If the object in the family has a low strength variable less than 25, it changes the colour by changing the animation frame of the target.
The problem is, and what makes the bug odd, it works about 95% of the time.
Some of the family objects do not get a target set to them at all, although some of the very SAME objects in the family are not ignored. And sometimes the colour setting is wrong.
If I release the button which turns the CTRL_LOCK global to 0 and then hold the button down again which returns CTRL_LOCK global back to 1, the ignored family members are triggered correctly.
This also off / on procedure also fixes the family members that have an incorrect target animation frame.
To summarise my questions.
1. Are these 4 lines of code efficient in their structure? is there a way of using less FOR EACH loops?
2. Why would some family members get ignored or wrongly set by this code?
image of code snippet
Humble thanks as always.