• 🏆 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] Can you use 2D arrays without setting array sizes?

Status
Not open for further replies.
Level 12
Joined
Nov 3, 2013
Messages
989
Title.

I know one of the arrays will never go over a certain size, so that's not an issue. But the other one could theoretically max out.


Now I could just pick a large enough number that will most likely never occur in any game, but I'd rather not if given the option.


Speaking of which, other variables where I don't set a specific array size become larger ingame as needed, right?




Off-topic, but if someone happens to know a way to use unit groups for units with the locust ability then for what I'm doing atm I'd rather just use a unit group
 
2D arrays only work with vJass. Once you pass 8191 indicies they will use function calls with multiple arrays instead. If you plan to go over that limit you're better off using hashtables or implementing the 2D arrays yourself.

WC3 Modding Information Center - VJASS Documentation

As for unit groups with locust, you can enumerate by player to catch them.
 
Level 12
Joined
Nov 3, 2013
Messages
989
2D arrays only work with vJass. Once you pass 8191 indicies they will use function calls with multiple arrays instead. If you plan to go over that limit you're better off using hashtables or implementing the 2D arrays yourself.

WC3 Modding Information Center - VJASS Documentation
So it's technically still just a single array?

My concern isn't really the number of indices per se, it's just that I'd prefer if the size would increase automatically as the index becomes higher during gameplay.


But anyway, I guess I'll just set some number I think will never be reached and it should be fine.

As for unit groups with locust, you can enumerate by player to catch them.
Does that mean that I could copy function CountUnitsInGroup takes group g returns integer and just replace CountUnitsInGroupEnum from call ForGroup(g, function CountUnitsInGroupEnum) with native GroupEnumUnitsOfPlayer takes group whichGroup, player whichPlayer, boolexpr filter returns nothing?

Well anyway I'll give that a shot and see if it works
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
The requirement for size is due to how they are implemented at a low level using JASS. A standard 1D array is split into rows using the other axis to select which row to read from. In order for this to happen the row length must be known and cannot change without all data being remapped.

As TriggerHappy suggested, if you want an unbounded, sparse 2D array then using a hashtable is recommended. Otherwise you can implement your own sparse data structure.
 
Status
Not open for further replies.
Top