How do I properly use the "for each ordered" loop

From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies. For use in game and custom works.
  • So I have a family consisting of 10 monsters with the Variables "IsTargetnumber" and "currenthealth". The Event goes "For each monster ordered by monster.currenthealth ascending"(so from low to high) perform action Stop Loop and set "IsTargetnumber" to loop index. The condition I have is:

    "monster.currenthealth must be greater than 0" (currently on 2 monsters have more than 0 health)

    The problem is regardless of my condition, the monsters with 0 health are still part of the loop index which becomes ( 0-9 because there are 10 monsters in total). But instead I a want a loop index of ( 0 and 1 because i want only 2 monsters included, the 2 monsters whos health are greater than 0)

  • If I'm understanding it correctly you need descending from high to low?

  • If I'm understanding it correctly you need descending from high to low?

    what im trying to do is have the monster with the least amount of health to have the smallest loop index number. If i did your way then the monster with the most amount of health left would have the smallest loop index number.

  • Ok I think I understand the problem you're describing but the point of the for each is to run through each instance to check which ones match the conditions and you can pick them, saying they must be 0 and 1 doesn't make a ton of sense. What are you trying to achieve with the loop or what data are you unable to gather?

  • Ok I think I understand the problem you're describing but the point of the for each is to run through each instance to check which ones match the conditions and you can pick them, saying they must be 0 and 1 doesn't make a ton of sense. What are you trying to achieve with the loop or what data are you unable to gather?

    So what im trying to do is have the enemy monsters target the player monsters to inflict a status affect.

    Enemies target whoever has the least amount of health and is alive. Sometimes these status affects activate at the same time the enemy monster attacks. If the attack so happens to kill the player monster at the same time, the status affect that was meant meant for the inital target moves to the next player with the least health.

    what im trying to do is even though the initial target dies, the status affect should NOT jump next in line and should instead disappear with the player monster that just died.

  • Is this because you are using a for each for the attack and then a for each for the status effect underneath? I guess it wouldn't find the instance if it was destroyed before the second event, but you could have them as one event. Status effect can be a function, you can pass the UID of the player through it so you know it is being applied to correct instance and if it was destroyed then function wouldn't do anything.

  • Is this because you are using a for each for the attack and then a for each for the status effect underneath? I guess it wouldn't find the instance if it was destroyed before the second event, but you could have them as one event. Status effect can be a function, you can pass the UID of the player through it so you know it is being applied to correct instance and if it was destroyed then function wouldn't do anything.

    for each is just to find out who has the smallest health. Status affect is a function. The status affect function is where all this occurs. I havent tried UID yet. I'll try that and get back to you.

  • Is this because you are using a for each for the attack and then a for each for the status effect underneath? I guess it wouldn't find the instance if it was destroyed before the second event, but you could have them as one event. Status effect can be a function, you can pass the UID of the player through it so you know it is being applied to correct instance and if it was destroyed then function wouldn't do anything.

    Oh wait youre right I have been using a for each to determine who to attack and another for each to determine the same target for the status affect. The reason for putting them seperate is due to the sheer number of different status affects and attack targets and all the monster there will be in the game.

  • When you find the target you should then apply effects in the same action, you can use one tidy function that applies status X from attacker X to target X, you can send both through the function as parameters. Sending UID through ensures you are picking the right target and it shows up in logging, it's good for minimizing bugs and gives you some control within the loops.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • When you find the target you should then apply effects in the same action, you can use one tidy function that applies status X from attacker X to target X, you can send both through the function as parameters. Sending UID through ensures you are picking the right target and it shows up in logging, it's good for minimizing bugs and gives you some control within the loops.

    Absolute legend man. It worked thanks for the help. Hopefully when my game is ever finished and you try it out I can send you some nice in game rewards. Thanks again.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)