Array Size

Status
Not open for further replies.
Level 5
Joined
Aug 6, 2009
Messages
136
So I was wondering before I got into triggering again.

I heard that array size 1 is from 0 - 10
Is this true?

If that's the case, what about the other array sizes?
Array size 2 = 20 then?

Thanks in advance
 
Level 25
Joined
May 11, 2007
Messages
4,650
No?..

You declare your array like Tempunit[20];

Then you have 20 + 1 unit variables named Tempunit

Like:
Tempunit[0] = Grunt;
Tempunit[1] = Bob;
Tempunit[2] = LordDz;
Tempunit[3] = AwesomeSauceDude;
Tempunit[4] = Grunt the Extreme Destroyer;
Tempunit[5] = Grunt;
etc
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I think he means GUI, and no, if you say array size is 1, it is really 1, but never set it to anything but 0, because it is fully useless.

What it does in the background is it tries to initialize every index from 0 to (the number - 1), so if I have Trigger array variable which says "Initial size: 10" it will create 10 triggers at indexes 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.

However this is not really good, because if you make few arrays that need to be constructed of size 8191(maximum), your map will fail to run initialization triggers properly, because you will hit "OP limit"(thats how we call it) before finishing initializing the variables.

Arrays in Jass are always of size 8191(indexes from 0 to 8190) and can not be made bigger or smaller. vJass does the same thing, but forces you to not use higher indexes(not true inside structs, which basically cuts the array into 8190/array_size pieces)
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
yes, because most of the GUI actions create the objects anyway, and then assign it into your variable, so you dont need to pre-initialize 8000 groups, when you actually create group almost every time you do anything with groups in GUI
 
Level 5
Joined
Aug 6, 2009
Messages
136
Well then, my questions have been answered.
+rep for ya mate!

Appreciate it.

Have a nice day!
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,241
JASS has no idea of "array size". Each variable you declare as an array has indices from 0 to 8191. In GUI the size field purely defines what indexes get an initial value.

It should be noted that the implementation of the arrays are dynamic growing arrays with the growth rate being in powers of 2. This means that using index 8191 will resize the array to full size (32 kb) where as using only the first 16 indices will use much less memory (<1 kb).

It should also be noted that due a bug with the save/load code, the contents of index 8191 are lost after a game is loaded.
 
every GUI action related to unit groups, as well as player groups does create group/force automatically.

Yes you need to create them, but I mean you dont need to initialize them at init, hence size can stay 0/1

This is not entirely true. When using add unit to unit group it does not create that unit group first. So the unit group and player group may be null.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
What it does in the background is it tries to initialize every index from 0 to (the number - 1), so if I have Trigger array variable which says "Initial size: 10" it will create 10 triggers at indexes 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.

GUI array variables are initialized upto the value. Meaning if initial size if 2, then indexes 0, 1, and 2 are initialized with the initial value.

It also creates groups for example upto the initial size. With the default size of 1, groups for indexes 0 and 1 are created automatically.
 
Status
Not open for further replies.
Top