Array question...

Status
Not open for further replies.
Level 8
Joined
Feb 20, 2020
Messages
220
How do i make an array of arrays?

i want to make a list of arrays,

listofarrays[1] = array1;
listofarrays[2] = array2;
listofarrays[3] = array3;

array1 [1] = unit x;
array1 [2] = unit y;;
array1 [3] = unit z;

so i can know the player and the unit of the player without conditions...
plase HELP!!!
 
Level 8
Joined
Feb 20, 2020
Messages
220
well i tryed to make that, but does not have this option...
the trigger works like that

- if a player gets a unit, i set the array at X for the player Y that gets the unit
- if i get a new unit, i set it at position x+1 for the player Y that gets the unit

- if other player gets a unit, i set the array2 at X for the player Z that gets the unit
- if the player Z gets another unit, i set the array2 at X+1 for the player Z that gets the unit

with that i will have 2 loop actions, one for the array of "players" and another for the array of list of monster.
 
Level 6
Joined
Dec 31, 2017
Messages
138
Units is Unit Group array of size 6.
  • For each (Integer A) from 0 to 5, do (Actions)
    • Loop - Actions
      • Unit Group - Pick every unit in Units[(Integer A)] and do (Actions)
        • Loop - Actions
          • Game - Display to (All players) the text: ((Name of (Player((Integer A)))) + ( owns + (Name of (Picked unit))))
Yes, this provides 2 loops.
 
Level 5
Joined
Jul 12, 2016
Messages
59
Could also use a hashtable in combination with an integer array.

Use the integer array to keep track of how many units each players have.
So if say, player 2 has 5 units then your integer is: IntegerArray[2] = 5. Whenever you gain a unit, add +1 to the integer accordingly.

After that you can save the unit in your hashtable, like so:

Bbvthuj.png
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
If using Lua one can make a table of tables which functions as a 2D dynamic array to some extent. Might need a custom deindex method.

Otherwise with JASS one will need to fragment a 1D array into multiple addressable smaller arrays which can be referenced by an index. One can then make an array of these indices and to some extent end up with a 2D array. If the sub arrays are all the same size one can use a uniform mapping to avoid this extra dereference at the cost of more math operators.
 
Level 8
Joined
Feb 20, 2020
Messages
220
well i need to know the exactly position of the unit, cant "pick every unit"
because i will do that to link a unit to a skill

player[1] cast "summon monster 1" - monsterlistplayer1[1] - summon the monster in the array in the position 1
player[1] cast "summon monster 2" - monsterlistplayer1[2] - summon the monster in the array in the position 2
player[1] cast "summon monster 2" - monsterlistplayer1[3] - summon the monster in the array in the position 3

player[2] cast "summon monster 1" - monsterlistplayer2[1] - summon the monster in the array in the position 2
and so on...
i need that so the trigger can work with any number of player, and the player know exactly which of his monsters he will summon.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
i need that so the trigger can work with any number of player, and the player know exactly which of his monsters he will summon.
If the maximum number of monsters for each player is constant then one can use the approach I suggested to above.

Say one wants a C/C++ style 2D array with definition of My2DArray[32][13]. One can break a single 1D array into 32 segments of 13 elements like the definition My1DArray[32 * 13].

To convert from the 2D array to the 1D array the following maths can be used...
My2DArray[player][monsterindex] -> My1DArray[player * 13 + monsterindex]

This is a very efficient approach to implement matrices and other 2D arrays where each axis has a constant size throughout the entire array.
 
Level 6
Joined
Dec 31, 2017
Messages
138
Do you know how large monsterlists should be?
If their size is known before they are used, you can use pseudo-2D array.
Let's say each monsterlist consists of N elements.
Then i-th element of j-th player's monsterlist is monsterlist[N*j+i]
 
Status
Not open for further replies.
Top