• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] picked unit loop inside picked unit loop

Status
Not open for further replies.
Level 21
Joined
Mar 29, 2020
Messages
1,237
hello there,

If I nest a "pick every unit in unit group" loop inside a "pick every unit in unit group" loop - which unit will be treated as picked unit?

will something like this work, or will it refer back to the first picked unit again?
  • Carried periodic
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in CarriedCasterGroup and do (Actions)
        • Loop - Actions
          • Set ID = (Custom value of (Picked unit))
          • Set CarriedCounter[ID] = (CarriedCounter[ID] + 1.00)
          • Unit Group - Pick every unit in CarriedDummyGroup[ID] and do (Actions)
            • Loop - Actions
              • Set CV = (Custom value of (Picked unit))
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,534
I believe it will use the most recent Picked unit, as if Picked unit is a global variable.

I usually set the first Picked unit (So the Caster in your case) to a variable like TempUnit, so it can be referenced inside the second Pick every unit function.

If that fails, you can always use a For Loop in combination with a Pick every unit function, although it shouldn't fail.
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
If I nest a "pick every unit in unit group" loop inside a "pick every unit in unit group" loop - which unit will be treated as picked unit?
Obviously, the picked unit inside the unit group you referred in the function;
Pick every unit in GroupA -> will pick units inside of GroupA
Pick every unit in GroupB (inside of GroupA) - will pick units inside of GroupB...

Remember each ForGroup() having a callback,
So GetEnumUnit() will only refer to the specified group and not from the outside of the function.

EDIT:

So the answer to your question:
will something like this work, or will it refer back to the first picked unit again?
Yes, it wouldn't refer to the picked unit inside of CarriedCasterGroup but from
CarriedDummyGroup[ID] instead: udg_ID and udg_CV would only refer to picked
units inside of each group they're declared in.
 
Last edited:
If during a "PickAllUnitsInGroup" an other "PickAllUnitsInGroup" is used, then "PickedUnit" might get an unexpected value.

Example:

GroupPickAll
- - Action_1 with PickedUnit()
- - GroupBPickAll()
- - - - Action_2 with PickedUnit()
- - Action_3 with PickedUnit()

Also, this does not necessarily need to happen directly visible. It can also run where you're not directly aware of, by other triggers, if they are fired inside the GroupLoop.

Example:

TriggerA - Some periodic event

Group_A_PickAll
- - Action_1 with PickedUnit()
- - Unit - Damage Units In Radius
- - Action_3 with PickedUnit()

TriggerB - A unit gets damaged event

Group_B_PickAll
- - Action_1 with PickedUnit()

===

So damaging a unit in from TriggerA will run all triggers with event "A unit gets damaged", for example TriggerB. There, "Picked unit" will get a new value. Now, when Action_3 from TriggerA runs, it has an unexpected value. This interfering problem might happen with all code that gets executed by actions from your GroupLoop.

Variables help, like @Uncle said.

===

Edit:

@JAKEZINC I might remember wrong but I also thought, like @Uncle, that PickedUnit can be treaten like a global, so even could be used from anywhere.
 
Last edited:
Status
Not open for further replies.
Top