• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Blowing my MIND: Add trained unit to unit group only works for PLAYER 1 !?!?!

Status
Not open for further replies.
Level 2
Joined
Apr 17, 2017
Messages
14
  • Units Trained
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
      • Unit Group - Add (Trained unit) to FalseAIAttackGroupOld[(Player number of (Owner of (Trained unit)))]
      • Game - Display to (All players) the text: (PlayerColors[(Player number of (Owner of (Trained unit)))] + ((Name of (Owner of (Trained unit))) + (|r now has an army. + (String((Number of units in FalseAIAttackGroupOld[(Player number of (Owner of (Trained unit)))]))))))

Something wrong happens.

The unit is detected, yet NOT added to the group. I really dont get it. Even if I set the trained unit to a variable.


I can only get this to work for the player in the first slot.


Every other part of the code works, meaning, it detects the correct player number for everything it just doesnt actually ADD the unit to the group.


The group always returns 0 if a player in any other slot





Any ideas? I thought this was something super basic and its literally making my entire code that comes after hogwash
 
Last edited:
Level 2
Joined
Apr 17, 2017
Messages
14
The array is only initialized with a group for index 1? Adding units to null will not do much.
I managed to produce some fairly successful maps not knowing this, fucking lol

The array is only initialized with a group for index 1? Adding units to null will not do much.
Why does it work for other things like players and virtually any other variable qithout setting the array size? just not unit groups..?
 
Last edited by a moderator:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,286
Why does it work for other things like players and virtually any other variable qithout setting the array size? just not unit groups..?
Because it does not work for them either. If you try to access a player array index that was not initialized it will return null as well, just like unit and player group variables.

When you are adding units to an existing unit group, you are not assigning the variable a new unit group object but rather access the existing object it points to. If you were to use one of the many GUI functions that do create new player groups to set the variable it will work for all indices even with a size 1. However if you try to add units to the unit group array outside the size without first assigning a group to that index then it will try adding the units to null which is not meaningful.
 
Level 9
Joined
Jun 13, 2010
Messages
365
Because it does not work for them either. If you try to access a player array index that was not initialized it will return null as well, just like unit and player group variables.

When you are adding units to an existing unit group, you are not assigning the variable a new unit group object but rather access the existing object it points to. If you were to use one of the many GUI functions that do create new player groups to set the variable it will work for all indices even with a size 1. However if you try to add units to the unit group array outside the size without first assigning a group to that index then it will try adding the units to null which is not meaningful.

So when you relate to a player owned unit or other variable, using array variables, you will have to increase the number from 1 to the number of players in the map?
 
Level 9
Joined
Jun 13, 2010
Messages
365
No. Increase array size (to size you're planning to use) only for
  • player groups
  • unit groups
  • timers

Okay so when i refer to a Variable_Integer(Player Number(Owner of Unit)), I do not need to increase the array size?

Meant Integer not unit.
 
Last edited:
Level 9
Joined
Jun 13, 2010
Messages
365
I guess it would. Just that GUI is very friendly for starters. :)

And then you just get too comfortable and used with it. :D
 
This is basically how it works:

All arrays in Wc3 have the same size: 8192 elements (8192 = 2^13).

There are two data types in programming: value types and reference types. Value types in Wc3 are integers, reals, and booleans. Reference types are everything else: units, timers, regions, etc. A reference type variable is different in that doesn't contain the actual value - it just points to a location in memory where the value exists, hence 2 timer variables can point to the same timer. The default value for reference types is "null". Value types can't be null, in Wc3 they are "0", "0.0", or "false" respectively.

In the GUI variable editor, you can specify how much of your array you are planning to use, and what starting value you want to give it. What this does is basically that the game loops through all these elements at map start and sets their value to your starting one. The array is still 8192 elements long, the rest is just not initialized. You can still assign values to uninitialized elements and use them if you want.

(A side note: Referring to handles as "reference types" is technically incorrect, although the principle is the same. Just in case Dr Super Good is reading this and thinking of correcting me.)
 
Status
Not open for further replies.
Top