- Joined
- Oct 12, 2011
- Messages
- 3,449
Erm.. Just a nice functionality of vJass. Dunno if this is going to be insta-gy-ed. Comment plz..
Code
Demo
Code
JASS:
library_once Array2D // v1.0.0
/****************************************************************************************
== Array 2D ==
by: Dalvengyr
I. Description
¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Allows you to declare a variable with 2 dimensional
index with max size of 1023.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
II. Disadvantages
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
- Can only declare global variable.
- Has max size of 1023.
III. API
¯¯¯¯¯¯¯¯
(Declaring new variable)
//! runtextmacro DECLARE_ARRAY_2D(PREFIX, TYPE, NAME, ROW_SIZE, COLUMN_SIZE)
PREFIX => variable prefix (private, public, etc.)
TYPE => variable type (integer, unit, string, etc.)
NAME => variable name
IV. Usage
¯¯¯¯¯¯¯¯¯
//! runtextmacro DECLARE_ARRAY_2D("private", "string", "SomeStr", "50", "1023")
You can use it like:
set SomeStr[0][0] = "hello" => at first index
set SomeStr[50][1023] = "world" => at max index
V. Link
¯¯¯¯¯¯¯
-
***************************************************************************************/
//! textmacro DECLARE_ARRAY_2D takes PREFIX, TYPE, NAME, ROW_SIZE, COLUMN_SIZE
type $NAME$_col extends $TYPE$ array[$COLUMN_SIZE$]
type $NAME$_row extends $NAME$_col array[$ROW_SIZE$]
globals
$PREFIX$ $NAME$_row $NAME$
endglobals
struct $NAME$_s extends array
private static method onInit takes nothing returns nothing
local integer i = 0
set $NAME$ = $NAME$_row.create()
loop
exitwhen i > $NAME$_row.size
set $NAME$[i] = $NAME$_col.create()
set i = i + 1
endloop
endmethod
endstruct
//! endtextmacro
endlibrary
Demo
JASS:
// Declare the variable
//! runtextmacro DECLARE_ARRAY_2D("", "unit", "Blabla", "10", "10")
struct Array2DDemo
static method onInit takes nothing returns nothing
local integer i = 0
local integer j
loop
exitwhen i > 10
set j = 0
loop
exitwhen j > 10
set Blabla[i][j] = CreateUnit(Player(0), 'hpea', 0, 0, 0)
set j = j + 1
endloop
set i = i + 1
endloop
set i = 0
loop
exitwhen i > 10
set j = 0
loop
exitwhen j > 10
call BJDebugMsg(I2S(GetHandleId(Blabla[i][j])) + " Named: " + GetUnitName(Blabla[i][j]))
set j = j + 1
endloop
set i = i + 1
endloop
endmethod
endstruct