2-dimensional arrays

Grundy

Ultra Cool Member
Reaction score
35
im not sure if this has been talked about anywhere, but using the arrays in the world editor you cannot make 2d arrays. i dont know if you can using JASS but i know you cant do it the normal way. there was a map i was working on where i needed 2d arrays and then i remembered back in my "advanced c++ programing" class we had to overloard the array index operator [] to work on a class object that held a 2d array in it. we had to convert 1-dimensional arrays into 2d arrays. heres how you can do it:

make an array of size [max_rows * max_columns], if you wanted a 3x10 2d array, for example, make an array of size 30. then when ever you want to access one of the elements in the array just plug in this formula for the index:
[((row-1)*max_columns)+column]
where "row" is the row that you want to access, "max_columns" is the total number of columns you have in the "2d array", and "column" is the column that you want to access.

in this example i'll use 3 rows and 10 columns, each row is for a stat, each column is for a hero:

[hero][ 01 ][ 02 ][ 03 ][ 04 ][ 05 ][ 06 ][ 07 ][ 08 ][ 09 ][ 10 ]
[STR][ 01 ][ 02 ][ 03 ][ 04 ][ 05 ][ 06 ][ 07 ][ 08 ][ 09 ][ 10 ]
[INT][ 11 ][ 12 ][ 13 ][ 14 ][ 15 ][ 16 ][ 17 ][ 18 ][ 19 ][ 20 ]
[AGI][ 21 ][ 22 ][ 23 ][ 24 ][ 25 ][ 26 ][ 27 ][ 28 ][ 29 ][ 30 ]

now if i want to get hero4's AGI you can see that it's index 24 but just so you dont have to look at a table every time you can simply plug in the forumla
((row-1)*max_columns)+column
AGI is row 3
(( 3 -1)*max_columns)+column
max_coumns will always be 10 for this array
(( 3 -1)* 10 )+column
hero4 is column 4
(( 3 -1)* 10 )+ 4
(( 3 -1)* 10 )+ 4 = (2 * 10) + 4 = 20 + 4 = 24

every time you want to get a stat for a hero you just plug in the row and column in the formula and the game will take care of the rest.

before anyone says you can just use actions functions to find a hero's stats, this is different. i used this in my map for stats per level. i set all of them to 0 and every time a hero learned a certain ability they would gain more stats per level, ex:

a hero learns an ability
learned ability equal to evasion
set stats[((3-1)*10)+<playernumber of owner of hero>] equal to stats[((3-1)*10)+<playernumber of owner of hero>] + 1

and

hero gains a level
add stats[((1-1)*10) +<playernumber of owner of hero>] to leveling hero's strength
add stats[((2-1)*10) +<playernumber of owner of hero>] to leveling hero's intelligence
add stats[((3-1)*10) +<playernumber of owner of hero>] to leveling hero's agility

this could be useful to some of you who want to use 2-dimensional arrays.
 
Oooh nice. I don't think I'll be doing that in my LoaP map, at least for the moment, but I'll give you credit if I do.

I took some C++, but I didn't recall learning that. Then again, I never finished...I quickly moved onto Physics and Calculus :D
 
Took the words right out of my mouth...Also:

What are they used for?
 
Sorting mainly.

I suppose he's saying you can draw one up with only one array. Label Str for hero 1 to, say Int for hero 10 in about 30 values. Now as opposed to creating different arrays and making a mess of a trigger, he points out an equation for finding which stat is in the blah array. I don't know if you can understand what I mean, but I do suppose this is helpful. Basically, hero 4 needs to find his agility. Where in the array is that? If it's a big array, you're going to have to have one HECK of a memory to know where it is. So, instead of just putting a numerical value when you're calling the array, put in your equation and the map will find it for you, swiftly and accurately if you understand and follow his instructions.

It MIGHT be helpful once my house array gets big enough, but I seriously doubt that'll happen. I have everything numbered to the max. Alexander should take a look at my trigger organization scheme in the WE :D
 
*gapes as that entire message just sort of goes in one ear, scrambles his brain, and leaves with a hooker in tow, smoking a cigar...*
 
:eek:

*Sighs*

:D:D:D

Hahaha! Well, thanks for the laugh, Alexander. That was a very unique way of expressing your opinion about my attempt at explanation :D

You have a 30 value array. Array space 1 is Hero 1's Strength. Array space 2 is Hero 2's Strength. And then so forth. Finally Array space 30 is Hero 10's Intelligence, or something of the sort.

Now, your hero just learned an ability or gained an item that gives multiple bonuses, perhaps one including attribute bonus. Where the heck is Hero 4's (assuming he's the hero receiving the bonus) intelligence stat? If you tell it what hero to look in and give it what row to look for via equation, the Map will see that Hero 4's intelligence is Array[24] via the equation he explains. Now you can simply set this found array to the value in question.

It's just so that you don't have to write down a diagram of which variable goes where if you're using 1 array to hold all of your hero values. I use 1 array to hold my house values.

Now, this whole process isn't needed if you feel like clogging up your variables list. Simply create a variable for everything in question, or an array for each variable in question for each hero. Either way, this process seems to be more efficient than clogging up your place with many variables.

Still don't get it? Ah well, doesn't matter. Maybe I'll be one of the only ones who profits off of this mention :D
 
*gapes as he suddenly realizes the idea didn't leave with a female hooker*

I GOT IT! :D
 
Or maybe the hooker was caught by the police and the idea when back in the head to hide :cool:
 
Don't know if this is useful or not, but NagelBagel summarized this on the bnet forums last month:


Usually the way to make multidimensional arrays is to just use a single array and fake it like this:


Footswitches[((INNER_SIZE * OUTER_INDEX) + INNER_INDEX)]

for an array that you would normally access like this:

Footswitches[OUTER_INDEX][INNER_INDEX]


INNER_SIZE is just the size of the inner set of arrays. (One more than it is possible for INNER_INDEX to be.)
 
3-dimensions are possible too but it gets a lot more complicated and i cant think of any situation that i would use more than a 2-dimensional array.
for anyone who still doesnt understand this, consider the following:
normally if you wanted to hold integers in an array with strenght, agility, and intelligence for 10 different heroes you would either have to do:
HeroStrength[10]
HeroAgility[10]
HeroIntelligence[10]
3 different arrays of size 10, or:
Hero1[3]
Hero2[3]
Hero3[3]
Hero4[3]
Hero5[3]
Hero6[3]
Hero7[3]
Hero8[3]
Hero9[3]
Hero10[3]
10 different arrays of size 3.
using a 2-dimensional array all you need is
HeroStats[30]
1 array of size 30 (10x3)
but using a 2-dimensional array in an array thats really only 1-dimension can get tricky unless you make a chart showing which hero and which stat is in each index. but then it can be a pain in the ass to go back and look at your chart every time you want to use one of the integers in the array. the formula i gave you up the original post will automatically do it for you. now all you have to remember is the column = hero number
row = 1 for str, 2 for int, 3 for agi
and you can have this "((row-1)*10)+column" in the index and you can just copy and paste it and then all you have to do is click on row and change it to the row you want and click on column and change it to the column you want.
You don't even have to understand how it works, just know that it does work. this way is easier and more organized.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    Mayo also has vinegar. Vinegar is a very important part of it, it's effectively a delivery method FOR vinegar but hidden
    +1
  • Varine Varine:
    It's a neat ingredient. But yeah it's eggs. But a LOT of people think eggs count as dairy because of the fucking food pyramid the US keeps trying to make a thing
  • Varine Varine:
    I think on the new one they did change it, but idk. I don't really care whatever the government is doing right now because it's consistently absurd. Like what is RFK doing in charge of health anything? I love the bear story because WTF was that, but also, pretty much every time he talks it's WTF. Like even his voice sounds microwaved
    +1
  • Varine Varine:
    The pyramid is fucking dumb as shit, no matter how you arrange it.
  • Varine Varine:
    It's actually remarkably easy to make mayonnaise though. Fun fact, it USED to kind of be a French mother sauce. I believe that Careme considered it one, it may have been aioli but that has also built a different meaning than it used to. An aioli is just mayonnaise I mixed with other shit typically, I didn't start it don't come at me
  • Varine Varine:
    It's very hard to do it on a large scale though
  • Varine Varine:
    Depending on how you pour the oil the consistency can vary wildly, but that's true for most emulsions. I can only make about two quarts at a time with my robo coup, and if I have to make several in series because I forgot to order it becomes really obvious even when I do it. We have to wait and mix them all together to make sure we have the same thing.
  • Varine Varine:
    Hollandaise is also kind of like that, emulsions require a very steady hand to do exactly the same every time.
  • Varine Varine:
    Luckily I live in an age with electricity so it's way fucking faster, but when I was just a boy trying to find my place I had some hardcore chefs that made use do things like that by hand. It is WAY easier to get right by hand because you control it and can feel it, but it takes soooooo much longer. And on the scale a modern kitchen requires... I serve 400-500 guests on average per day right now, if I had 100 then we could do things way better
  • Varine Varine:
    But we can't do that. In the winter yeah, but I HAVE to get people through here right now so I can afford the staff that we CAN do that. We have about 100 days of summer, and if that summer doesn't make us what it will, then I can't operate the other most of the year with my staff. The owner is talking about closing two days a week to cut down on labor, I told him he should cut down on vacations and it did not go great. I do think I won though, I have to keep my fucking core staff and they have to be gainfully employed
  • Varine Varine:
    Sure some of them might take a second job, but I can't just cut my entire staff to unlivable hours, nor can I can cut them off all winter if I want them to come back.
  • Varine Varine:
    And also, there is no fucking way I'm pulling these hours come september. I only do this right now because I have to, the second I don't have to be the one doing it I won't be
  • Varine Varine:
    I have a 5 person core staff in the kitchen, not including me or Chef Ben
  • Varine Varine:
    Though two of those people are likely not making it this year. One of them has been replaced, the other I am kind of trying to. He's being a giant bitch, today I had to get onto him because in the three hours before I left he had taken like thirty minutes for cigarette breaks
  • Varine Varine:
    And he was also complaining to me the other day that he was out of weed so couldn't smoke any before work that day, and was confused about why I was annoyed he was telling me, his boss, that he is smoking weed everyday before work.
    +1
  • Varine Varine:
    Like yeah I can tell. I don't need to fucking know.
  • Varine Varine:
    So now he's getting scrutinized and will not be top of the list. I know I don't have the smartest people but I do expect them to have some common fucking sense
  • Varine Varine:
    I did do a rare thing for me and hire a girl last month without warning. Everyone was made at me because I started her at like 21, but she worked with me before and I was like don't care. She made 19 at her old job and I wanted her to come work with me, she is the best
    +1
  • Varine Varine:
    I'm going to get her a raise at the end of the summer. She wants to go to school again, but I want her to still work with me so.... she kind of can just tell me what the price is. I can go to 25 if she keeps up. I need to get her onto line more, that's what she wants, but I need her where she is and it's not fair that she doesn't get the little bit of raise that comes with it. She can do it no problem, I've worked with her there.
  • Varine Varine:
    It's just hard to move and train people unnecessarily right now. And also the line fucking sucks, it's not any more fun. This is turn and burn so I have the bankroll, and everyone suffers for it
  • Varine Varine:
    Eventually we'll get it balanced, we'
  • Varine Varine:
    we're starting online orders and stuff, but I also turn that off all the time because I barely keep up trying to be the best at Sysco shit
  • Varine Varine:
    I think it's gonna be a good fall and winter though. We're going to have a good staff, they will get along, they will be able to manage the workload and the complications, they know how to really cook this year, like every person on line knows their steak temps. Some of them use thermometers a lot and they don't always use them right, but they do know how to do it. Failure, especially in this field, is the only way to get better. They'll get it
  • Varine Varine:
    They won't get feel down while they do the thermometer, but we didn't have an instant read probe when I was learning. Like they did but god knows how off it is, you HAD to do it by feel. Even if the chef was fine with me bringing my own, it takes too long. Poke and know
  • The Helper The Helper:
    420 threads in the Artificial Intelligence forum :)

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials
      Top