Warcraft III resources & community, 2003–2006 · archived

Multi-Array

not rated
Submitted by AyaneVariable Change0 downloads
It is a system of variable multi-array. Compatible all var type with only one type in all array of multi-array. Functions presented is for var integer or string, but it is very easy to change the type of the variable (ex:unit).
A array parent of array can also contain values.
In order to read in a array it is necessary to open it.

**Functions description**
function CreateArray takes nothing returns nothing
Create a array in the array in course

function SelArray takes integer IdArray returns boolean
Open the array indexed < IdArray > of the array in course
If the array does not exist then return over ' False', if not return' True'

function SelPArray take integer NbParent returns boolean
Open array relative of the array in course
Execute the action above < NbParent >.
Return' False' if the array does not have a relative (i.e. array 0)

function ReadArray takes integer ValId returns integer
Return the indexed value < ValId > of the array in course
If the index does not exist then return ' - 1 '

function CountVArray takes integer IdGArray return integer
Return the number of values indexed in array < IdGArray >.
Caution it acts of the general index, not of the index of the array in course
If the index indicated does not exist then return ' - 1 '

function CountArray takes integer IdGArray return integer
Return the number of arrays indexed in array < IdGArray >.
Caution it acts of the general index, not of the index of the Array in course
If the index indicated does not exist then return ' - 1 '

function GetArray takes nothing return integer
Retourne the general index of the array in course

function AddArray takes integer valley returns nothing
Add < valley > to the array in course

function ValArray takes integer ValId, integer valley returns nothing
Allot < valley > to the index < ValId > of the array in course
If the index then does not exist there to create this in their allotting value -1.


** Maps Example **
Integer: Debug Map
http://metalplanet.org/forums/attachment.php?attachmentid=2191

String: Treeview
http://metalplanet.org/forums/attachment.php?attachmentid=2192


** Installation **
To create the following variables of the integer type:
Name: array: Default:
va_ArrayVal True
va_PosArray True
va_ArrayParent True -1
va_pos False -1
va_NbArray False
va_ArraySel False

Then to copy the following lines in code personalized script

Source

// For Multi-array integer
function CreateArray takes boolean sel returns nothing
	set udg_va_NbArray = udg_va_NbArray + 1
	set udg_va_ArrayParent[udg_va_NbArray] = udg_va_ArraySel
	if sel then
		set udg_va_ArraySel = udg_va_NbArray
	endif
endfunction

function SelArray takes integer IdArray returns boolean
	local integer i = 0
	local integer a = 0

	loop
		if (udg_va_ArrayParent[i] == udg_va_ArraySel) then
			if (a == IdArray) then
				set udg_va_ArraySel = i
				return true
			endif
			set a = a + 1
		endif
		exitwhen i == udg_va_NbArray
		set i = i + 1
	endloop
	return false
endfunction

function SelPArray takes integer NbParent returns boolean
	if (udg_va_ArraySel > 0) then
		set udg_va_ArraySel = udg_va_ArrayParent[udg_va_ArraySel]
		if (NbParent > 0) then
			return SelPArray( NbParent - 1 )
		else
			return true
		endif
	else
		return false
	endif
endfunction

function ReadArray takes integer ValId returns integer
	local integer i = 0
	local integer a = 0

	loop
		if (udg_va_PosArray[i] == udg_va_ArraySel) then
			if (a == ValId) then
				return udg_va_ArrayVal[i]
			endif
			set a = a + 1
		endif
		exitwhen i == udg_va_pos
		set i = i + 1
	endloop
	return -1
endfunction

function GetArray takes nothing returns integer
	return udg_va_ArraySel
endfunction

function CountVArray takes integer IdGArray returns integer
	local integer i = 0
	local integer a = 0

	if (IdGArray > udg_va_NbArray) or (IdGArray < 0) then
		return -1
	elseif (udg_va_pos == -1) then
		return 0
	else
		loop
			if (udg_va_PosArray[i] == IdGArray) then
				set a = a + 1
			endif
			exitwhen i == udg_va_pos
			set i = i + 1
		endloop
		return a
	endif
endfunction

function CountArray takes integer IdGArray returns integer
	local integer i = 0
	local integer a = 0

	if (IdGArray > udg_va_NbArray) or (IdGArray < 0) then
		return -1
	else
		loop
			if (udg_va_ArrayParent[i] == IdGArray) then
				set a = a + 1
			endif
			exitwhen i == udg_va_NbArray
			set i = i + 1
		endloop
		return a
	endif
endfunction

function AddArray takes integer val returns nothing
	set udg_va_pos = udg_va_pos + 1
	set udg_va_ArrayVal[udg_va_pos] = val
	set udg_va_PosArray[udg_va_pos] = udg_va_ArraySel
endfunction

function ValArray takes integer ValId, integer val returns nothing
	local integer i = 0
	local integer a = 0

	loop
		if (udg_va_PosArray[i] == udg_va_ArraySel) then
			set a = a + 1
			if (a == ValId) then
				set udg_va_ArrayVal[i] = val
				return
			endif
		endif
		set i = i + 1
		exitwhen i == udg_va_pos
	endloop

	set i = ValId - a

	loop
		if (a == i) then
			call AddArray( val )
			return
		else
			call AddArray( -1 )
		endif
		set a = a + 1
	endloop
endfunction

// For multi-array string
//modified va_ArrayVal type:string
function CreateArray takes boolean sel returns nothing
	set udg_va_NbArray = udg_va_NbArray + 1
	set udg_va_ArrayParent[udg_va_NbArray] = udg_va_ArraySel
	if sel then
		set udg_va_ArraySel = udg_va_NbArray
	endif
endfunction

function SelArray takes integer IdArray returns boolean
	local integer i = 0
	local integer a = 0

	loop
		if (udg_va_ArrayParent[i] == udg_va_ArraySel) then
			if (a == IdArray) then
				set udg_va_ArraySel = i
				return true
			endif
			set a = a + 1
		endif
		exitwhen i == udg_va_NbArray
		set i = i + 1
	endloop
	return false
endfunction

function SelPArray takes integer NbParent returns boolean
	if (udg_va_ArraySel > 0) then
		set udg_va_ArraySel = udg_va_ArrayParent[udg_va_ArraySel]
		if (NbParent > 0) then
			return SelPArray( NbParent - 1 )
		else
			return true
		endif
	else
		return false
	endif
endfunction

function ReadArray takes integer ValId returns string
	local integer i = 0
	local integer a = 0

	loop
		if (udg_va_PosArray[i] == udg_va_ArraySel) then
			if (a == ValId) then
				return udg_va_ArrayVal[i]
			endif
			set a = a + 1
		endif
		exitwhen i == udg_va_pos
		set i = i + 1
	endloop
	return ""
endfunction

function GetArray takes nothing returns integer
	return udg_va_ArraySel
endfunction

function CountVArray takes integer IdGArray returns integer
	local integer i = 0
	local integer a = 0

	if (IdGArray > udg_va_NbArray) or (IdGArray < 0) then
		return -1
	elseif (udg_va_pos == -1) then
		return 0
	else
		loop
			if (udg_va_PosArray[i] == IdGArray) then
				set a = a + 1
			endif
			exitwhen i == udg_va_pos
			set i = i + 1
		endloop
		return a
	endif
endfunction

function CountArray takes integer IdGArray returns integer
	local integer i = 0
	local integer a = 0

	if (IdGArray > udg_va_NbArray) or (IdGArray < 0) then
		return -1
	else
		loop
			if (udg_va_ArrayParent[i] == IdGArray) then
				set a = a + 1
			endif
			exitwhen i == udg_va_NbArray
			set i = i + 1
		endloop
		return a
	endif
endfunction

function AddArray takes string val returns nothing
	set udg_va_pos = udg_va_pos + 1
	set udg_va_ArrayVal[udg_va_pos] = val
	set udg_va_PosArray[udg_va_pos] = udg_va_ArraySel
endfunction

function ValArray takes integer ValId, string val returns nothing
	local integer i = 0
	local integer a = 0

	loop
		if (udg_va_PosArray[i] == udg_va_ArraySel) then
			set a = a + 1
			if (a == ValId) then
				set udg_va_ArrayVal[i] = val
				return
			endif
		endif
		set i = i + 1
		exitwhen i == udg_va_pos
	endloop

	set i = ValId - a

	loop
		if (a == i) then
			call AddArray( val )
			return
		else
			call AddArray( "" )
		endif
		set a = a + 1
	endloop
endfunction

Comments

3
Game cache would never be slower than a giant loop and an array, and gamecache is not that slow anyways.
Game Cache is too slow (I didn't use THAT array, but Game Cache is)
hmn, really, just use GameCache