HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Simulating Nested Arrays

12-23-2003, 10:45 AM#1
th15
I've searched the forum and it seems that JASS doesn't do nested arrays, which just sucks.

Anyways, I need to store 8 unit variables per player and i want to access them easily.

Its a tank commander game a little like battleship command where you control a tank with turrets attached. I need this trigger to move all of a player's turrets to the position of his tank.

Event:
Periodic time - every 0.5 seconds

Action:
Pick every player matching slot status = is playing AND player control = human
Do: For each integer 1-8 do...
Move PlayerTurret[(Picked PlayerNumber*9)+For loop integer A] to position of PlayerTank[Picked PlayerNumber]

Sorry bout the formatting but is this the best way to do it? I'm planning to have 10 players and i hope i won't have to write every turret-related trigger ten times.

Edit: Another question. Does anyone know what the "Combat Attack 1 - Damage Factor - Medium" field in the object editor does?
12-23-2003, 12:12 PM#2
curi
well if it's only 8 just make 8 arrays and 8 loops.

or if you really want, you could have player 1 use slots 1 11 21 31 etc in the array. player 2 uses 2 12 22 32 etc then u can store 8 things per player in an array, and access by player-number + var-number * 10

make sure var numbers start at 0 if you use index 1.

or umm, if u wanna move all turrets to position of tank, why not just keep them in a unit group for the player? have an array of unit groups with each player's turrets, and ur set.
12-23-2003, 12:26 PM#3
th15
Thanks curi. I think i'll use your method, theres less arithmetic involved. Unit groups dont do it for me because different slots have different properties (i.e. slots 1-3 are heavy turret slots wheres slots 4-8 only hold light weapons)
12-23-2003, 04:53 PM#4
Ligature
I think you've got something here, th15. With very careful array management, this could really help out in situations where large, 2-dimensional arrays would be useful.

Of course, a 2-dimensional array would be better. But, say I'm trying to record 20 different stats for 20 different units. I don't want 20 different arrays - especially if the number of units might increase! Your idea would allow all those 20 arrays to be crammed into one huge array 20 times as big... which is essentially what a 2d array does.
12-23-2003, 05:18 PM#5
th15
Uhh the problem with my array is that since it wastes the indices from 0 to the first player multiple, you can only store so much. But it can handle indiced arrays larger than 1 digit

Curi's method requires a small array but doesnt allow you to have arrays larger than 9, 10 if you try harder. It does take alot less time to write his method in GUI though.

Arr it would be much simpler if JASS supported arrays like java :(
12-23-2003, 05:52 PM#6
l]arkOne
You can.

Player# + Level# * Slot#

Slot# = 12:
1,13,25... is player1
2.14,26... is player2
...

woa I was using this method without arithmetic(was setting Variable[1], Variable[13]...) This will save lot of time.
12-23-2003, 06:05 PM#7
Zechnophobe
What I think the above is trying to say: Decide on how many bits of data you want each player to have, or use a variable for that number (I'll call it DataNum, and have it be 10).

Then assign a FinalInt value representing an offset for each type of data, or just seperating groups of data(TURRET2 = 4) for instance. To find the Turret2 Data, for player 3:
PlayerNum(3)*DataNum(10)+TURRET2(4) = 34. At Index 34 is where your Turret2 info for player 3 would be. Get it?
12-23-2003, 06:52 PM#8
weaaddar
I use a function to do this (Its in like every map that I make)
Code:
function Ix takes integer x, takes integer y returns integer
return(x*ylimit+y)
endfunction
ylimit is an integer which is the max value that y will reach.
12-23-2003, 07:44 PM#9
Ligature
Quote:
What I think the above is trying to say: Decide on how many bits of data you want each player to have, or use a variable for that number (I'll call it DataNum, and have it be 10).
It's even better than that! If you work the array the same way people have been doing to record information about an undefined number of units - by recording the number of array members separately as an integer - you can make your 2-dimensional array resizeable as well!

For instance, I have a big array of items, but I want to break them up into categories. So separately, I keep an integer array to record how many items are in each category, and an integer (not an array) to record how many categories there are. That way when I want to add an item to a category, I just bump up all the array members in the main array after the last item of that category by one and set the number of items in the category to itself + 1. Similarly, if I want to remove a category, I just set the number of categories to itself - 1, drop all the items in the main array after the category being removed back by the number of items that category occupied, and bingo.