[General] Question about variable arrays

Status
Not open for further replies.
Level 25
Joined
Jun 26, 2020
Messages
1,971
When you create a variable array it has a size, so by logic, you can't never use a index the pass the size, exm you create a variable with size 10 so you never can use a index 11, but sometimes I see you can do this, if the size is 1 at least I think, is this because a variable array with size 1 means something or what?

Edit: sorry for the double-posting, that was a mistake.
 
When you create a variable array it has a size, so by logic, you can't never use a index the pass the size, exm you create a variable with size 10 so you never can use a index 11, but sometimes I see you can do this, if the size is 1 at least I think, is this because a variable array with size 1 means something or what?
This is because JASS has no concept of array "size". All arrays are dynamic arrays (expand as needed) with a maximum size as defined by the maximum size constant.

All the size field does is initialize up to size indices with the specified value. This is useful for complex types that need an initial value such as player and unit groups. Another example use case is for initial data such as when an array is used to map a player to a value the size field can be used to initialize the value for every player instead of needing a loop in a trigger.

If you look at the resulting map script you will see that the size field controls the initialization loops that GUI generates for variables. This is why very large sizes should be avoided as with enough such large sized arrays the initialization thread can crash due to reaching the op limit resulting in triggers not getting initialized.
 
Status
Not open for further replies.
Back
Top