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

How to make 2D array?

Status
Not open for further replies.
Level 6
Joined
Jun 29, 2011
Messages
181
Hello i'm creating some stuffs for a map and i need 2D array, i tried to do it with "type" that seems to works like typedef in c++ but i don't know how to use it :/
Can someone help me :)?
 
In Jass, arrays have an index limit of 8191 (but we use up to 8190 since 8191 is buggy in saved replays ;/

You can make your own 2-D array given a size for one of the indicies:

JASS:
globals
    private integer array data
    private constant integer SIZE_INDEX = 15
endglobals

function Save2D takes integer index1, integer index2, integer int returns nothing
    set data[index1 * SIZE_INDEX + index2] = int
endfunction

function Load2D takes integer index1, integer index2 returns integer
    return data[index1 * SIZE_INDEX + index2]
endfunction

As long as the second is index is between 0 and 14 here, you'll be fine ;)
You can change SIZE_INDEX if you want.

But beware, if the first index is high enough, this will never work ;/
In this case, the maximum possible value for the first index is 546 (8190/15)
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
vJass also offers the possibility of 2D arrays.

And btw i don't know about replays but using the index 8191 of an array variable makes a saved game unable to be played (wc3 crash on loading).
Or maybe it is fixed with the newest patches.
 
Status
Not open for further replies.
Top