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

[General] Default Array Size Index issues

Status
Not open for further replies.
Level 3
Joined
Sep 14, 2011
Messages
47
Okay - so I recently learned that WC3 doesn't enforce array size limits, and as such, the values you set for them in the variable editor are meaningless.

So I proceeded to change all array sizes to 1 (hoping this would save memory by having less big arrays initialized), and those whose default setting had been modified I set manually with triggers. Now after doing this I'm having all kinds of issues in my map. Anyone know what types of issues I might be running into?

THanks +REP for suggestions
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
Arrays ALWAYS have the size 8192.

The value for array size you can enter in the GUI Variable editor only means which fields of the array will be initialized with the default value you chose.
The normal default values are:
integer: 0
real: 0.0
string: "" (empty string)
boolean: false
etc.

Now if you create a new integer array variable in the GUI Variable editor with "size: 5" and "default value: 1" then the array will be initialized like this:
myArray[0] = 1
myArray[1] = 1
myArray[2] = 1
myArray[3] = 1
myArray[4] = 1
myArray[5] = 0
myArray[6] = 0
myArray[7] = 0
...
myArray[8191] = 0

Memorywise it doesnt matter which size you chose because the array always requires the same space, if its full or empty or whatever.. (technically this is not 100% correct, but its good enough, dont worry about it).

One thing: having a lot of array variables with high "size" CAN cause problems with the op limit. However this is unlikely, just dont put all your arrays on "size = 8191" if you dont need it.
Reason: to fill the array with your chosen default value wc3 loops through the array at map start. If it has to loop too many times it might reach op limit.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
It is not really unlikely to hit the op-limit setting a lot of variables to 8191.
I have seen a lot of people hit the op-limit because of this.
Arrays require more space the more that get initialized. They are initialized in pairs (from what i remember). Meaning when you set value to index of 1. Indexes 0 and 1 get initialized if they haven't been initialized before.
There is a list of variables which have to be initialized in GUI variable editor along with another explanation of the variable editor in my tutorial Things To Know When Using Triggers / GUI.
 
it will return an empty string not a string saying "null"

"null" is a valid non-empty string, empty string is empty

If you set 1 for the types that need to be initialized (like unit groups), you will only be able to use the index 1 since all the other indices won't be initialized with the group creation method...
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Timer variables, for example, in GUI should still be initialized to the max index you need because GUI does not provide CreateTimer-functions and many GUI users forget/do not know that there has to be a valid timer object behind the variable in order to e.g. start it. I always compare it to units. Just because you created a unit variable does not mean you created a unit. It's not the variable you run actions on but the object it points to.
 
Status
Not open for further replies.
Top