HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Can anyone help me out with arrays?

08-31-2002, 01:24 AM#1
Guest
I can't figure out what they do and why I should use them over any other options...so...anyone able to give a small description and possibly a simple example of their use?

Thanks in advance...
08-31-2002, 02:19 AM#2
Guest
I just posted a tutorial on creating a rank displayer out of the food counter in War3 for custom games, and the setup makes use of arrays. You can go to it here. ;)

Hope this helps...
08-31-2002, 02:40 AM#3
Guest
An array is like a list of variables that can be accessed with the same name. You use an "index" to access each individual value in the array.

my_array[0] = 100
my_array[1] = 230
my_array[2] = 45
my_array[3] = 210
my_array[4] = 650

One good use of an array is to use a for loop to easily access all of the values in one statement.

For Integer A = 0 to 4 do Game text message "my_array contains" + my_array[Integer A]

You can also pick one of the values you store in an array at random.

unit_array[0] = footman
unit_array[1] = ghoul
unit_array[2] = archer
unit_array[3] = grunt
unit_array[4] = treant

Create 1 (unit_array[random integer between 0 and 4]) for Player 1

You can also associate the array index to a player number. This is what I use arrays for the most, I think.

playerhero[1] = hero for player 1
playerhero[2] = hero for player 2
playerhero[3] = hero for player 3
playerhero[4] = hero for player 4
playerhero[5] = hero for player 5
playerhero[6] = hero for player 6
playerhero[7] = hero for player 7
playerhero[8] = hero for player 8

Then say you want to give all heroes an ankh of reincarnation... rather than have 8 actions, you can simply do:

For Integer A = 1 to 8 do Create ankh of reincarnation and give to playerhero[Integer A]

Or if you want a player's hero to increase a level when he discovers a rare artifact.

Event
Unit enters region
Action
Set level of playerhero[player index of (owner of (triggering unit))] to (playerhero[player index of (owner of (triggering unit))] + 1)

Okay, that last one was pretty complicated, but if you understand the logic it can save you lots of time and make your triggers much smaller and easier to manage. There are a lot of uses for arrays, it mostly depends on what you need to accomplish with your variables.

AV
08-31-2002, 02:42 AM#4
Guest
Uh ...ya...kinda, it's an example, but I still don't see why this is more interesting than an integer or something like that...
08-31-2002, 02:43 AM#5
Guest
Ave AV. U rock. Make that one sticky or put it up somewhere someone... nice and tight. Thx.