• 🏆 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!

Unit Group - Add Unit

Status
Not open for further replies.
Level 6
Joined
Jan 2, 2007
Messages
189
Does this function even work?

its a basic trigger thats supposed to deal 100 damage to units as a dummy unit passes through them. But for some reason the unit groups arent working and it deals 100 damage repeatidly.


  • Set ShockNova_Group[1] = (Units within 50.00 of Temp_Point[1] matching (((((Matching unit) is alive) Equal to True) and...blah blah
  • Unit Group - Pick every unit in ShockNova_Group[1] and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Picked unit) is in ShockNova_Group[2]) Equal to False
        • Then - Actions
          • Unit Group - Add (Picked unit) to ShockNova_Group[2]
          • Unit - Cause ShockNova_Unit[(Integer A)] to damage (Picked unit), dealing 100.00 damage of attack type Spells and damage type Normal
        • Else - Actions
 
Level 5
Joined
Sep 1, 2010
Messages
168
Only thing from your trigger might be as Waterknight said, that your array is too small.
If you have an array of size 2, thne the only values of that array are [0] and [1], not [1] and [2].
 
Level 6
Joined
Jan 2, 2007
Messages
189
hmm ok it worked! but i have a question now haha. why did i need to change the array size of the Unit Group Variable but for other arrays, such as an integer array, it works fine if i leave it to the default (0)? Is this because earlier in the trigger i set the integer variables? So say a said i did:


  • Set ShockNova_Int[1] = (ShockNova_Int[1] + 1)
But I didnt do this:

  • Set ShockNova_Group[2] = (whatever units...)
 
its because integers don't need to be initialized, while groups should be initialized... basically when you put the size on the variable editor, it initializes the indexes of the array (from 0 to the size) to the default value...

for groups, it also runs the CreateGroup() native, which is needed for you to be able to use the group...
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Yes but besides that integers are of a primitive type that hold their data themselves, object variables only point to the object. Now, arrays in jass are preset to initial values, object types would be set to null, to an invalid object that you cannot apply any functions on. Integer arrays are also preset to null or 0 and you can already operate sencefully with this value like binary addition.

But for a neat coding style you should initialize both.
 
Status
Not open for further replies.
Top