• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] What is the difference?

Status
Not open for further replies.
Level 3
Joined
Sep 26, 2012
Messages
39
What's the difference between these and which one should I use?

  • Set ScalperPickedGroup = (Units within 120.00 of ScalperDummyLoc matching (((((Matching unit) is A structure) Equal to False) and (((Matching unit) is Magic Immune) Equal to False)) and ((((Matching unit) is Mechanical) Equal to False) and ((((Matching unit) is alive) Equal to True)
  • Set ScalperDamageGroup = (Random 1 units from ScalperPickedGroup)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Number of units in ScalperDamageGroup) Greater than or equal to 1
    • Then - Actions
Or

  • Set ScalperPickedGroup = (Units within 120.00 of ScalperDummyLoc matching (((((Matching unit) is A structure) Equal to False) and (((Matching unit) is Magic Immune) Equal to False)) and ((((Matching unit) is Mechanical) Equal to False) and ((((Matching unit) is alive) Equal to True)
  • Unit Group - Pick every unit in ScalperPickedGroup and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in ScalperPickedGroup) Greater than or equal to 1
        • Then - Actions
          • Set ScalperPickedTarget = (Random unit from ScalperPickedGroup)
        • Else - Actions
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Neither.

Use:

  • Actions
    • Set ScalperPickedGroup = (Units within 120.00 of Scalp etc
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Number of units in ScalperPickedGroup) Greater than or equal to 1
      • Then - Actions
        • Set ScalperPickedTarget = (Random unit from ScalperPickedGroup)
      • Else - Actions
    • Custom script: call DestroyGroup(udg_ScalperPickedGroup)
 
Level 3
Joined
Sep 26, 2012
Messages
39
Thank you sir, though is there a downside to ''Picking all units'' in a certain group, suggesting the group ends up being cleared and destroyed?
 
I can one-up you and name an even better method - since your group doesn't need to persist its contents, you can use a global group, thus avoiding creating and destroying them each time the trigger runs (a huge optimization)

JASS:
scope example initializer i
    globals
        private group grp=CreateGroup()
    endglobals
    
    private function i takes nothing returns nothing
        call GroupEnumUnitsInRange(...)
        //now get a random unit and do your stuff with it
        //voila, you never have to dynamically create and remove groups
    endfunction
endscope
 
Status
Not open for further replies.
Top