• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Question about variable arrays

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,852
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.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,195
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.
Top