HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

A Guide to Arrays (help out with this one) :)

12-05-2002, 07:00 PM#1
Guest
Arrays are funny, simple things that seem to elude me as per their use. I think other people who are non-programming types also get confused by their purpose, so let me see if my explanation may be correct, as it's a pretty simpleton version and might help others to understand it.

What an Array is used for:
An arrays purpose would to be to 'hold' a certain type of countable variables that would be defined in a normal variable function.

I.e., in the world editor:

Event:
When unit enters region

Condition:
(none)

Action
For every Integer A (number) to (number) do Set numberofunits=Integerarray(integerA)

NumberofUnits would be a Unit set variable, IntegerArray(i) would be an Integer Array (duh :p) with i being set to a Integer type variable.

This type of Trigger would effectively grab any unit who enters our defined region and put them into a variable called NumberofUnits.

If this setup is wrong (i'm doing this out of memory) please let me know and I'll fix this formula so others can see it correctly.

Another way to think about Integer Arrays is like this. Say I have 15 children. An unknown amount of them will be going to the grocery store today. I don't know how many so I would setup an Integer Array to help count each one who enters the market. I could then, at the end of the day, look at my Integer Array and see how many went.

Most of this might be wrong, help me to make it correct guys. I think this would help out a majority of us beginners to become better, and more informed, trigger designers :) (which means less questions for you!)
12-05-2002, 07:15 PM#2
Electromancer
Heh, i had this same question. What you do is do a integer loop A, which is at the top of actions, and it says something like "For every Integer A (number) to (number) do Set numberofunits=Integerarray(integerA). And if thats not what you wanted, then please be a bit more specific.
12-05-2002, 07:21 PM#3
Guest
Hey cool, actually I'm not desiging the above situation, just trying to give it as an example for beginners such as myself to keep Integer Arrays in their head straight. Are my worded examples correct in theory, or how would you explain Integer Arrays? Lets get this guide going =)

Doesnt:

For every Integer A (number) to (number) do Set numberofunits=Integerarray(integerA)

mean that we would know how many units were on the map at once (i.e. 1 to 30). What if we didn't know how many units were on the map at any given time (i.e. in random spawn situations), how would you setup the integer array then to count any unit entering the region? Thanks! :D
12-05-2002, 09:48 PM#4
Axiverse
in we it's
arrayname[i]
not
arrayname(i)

as you can see i have nothing better to do...
12-05-2002, 09:54 PM#5
SuperIKI
No, you got arrays wrong I think.
I'm not good at explaining, but I'll try.
Imagine this:
There are 5 units.
You want to kill them all (MUHAHAHAHA).
So you make an array of units called 'arr' and put them all in.
The first unit becomes arr[0].
The second unit becomes arr[1].
The third unit becomes arr[2].
The forth unit becomes arr[3].
The fifth unit becomes arr[4].
And now you can loop:
For integer a=0 to 4 do: Kill arr[integer a]

Got it?
Basically you can't count the number of entries in an array in JASS. But that depends on your algorithm.

If you don't get me, it's maybe me, because it's almost midnight over here. Good night.
12-05-2002, 10:07 PM#6
The_Cyberdemon1
Arrays work extremely well for keeping track of kills/rounds remaining in a weapon.

Event:
----A unit owned by (enemy 1) dies
Condition:
----Owner of (killing unit) not owned by (enemy 1)
Action:
----Set Kills[(player number of (owner of (killing unit)))] = Kills[(player number of (owner of (killing unit)))] + 1.

Ammo
Event:
----A unit owned by (enemy 1) dies
Condition:
----Owner of (attacking unit) not equal to (enemy 1)
Action:
----Add -1 to (owner of (attacking unit)) current gold
----Set varaible ammo[(player number of (owner of (attacking unit)))] = ammo[(player number of (owner of (attacking unit)))] - 1

there
12-05-2002, 10:25 PM#7
DKSlayer
I can do a Tutorial/Helper for JASS Array's when I get home too. Already got one a functions. It's in the AI forum under AI and JASS FAQ. Tell me what you think and criticise it.
Thanks
DKSlayer
12-05-2002, 10:31 PM#8
ph33rb0
Why would you need an array to count how many are going to the market? You can do that in an integer variable. If you want to see which ones, then it would be a different story, and then you'd probably use booleans.
12-06-2002, 01:25 AM#9
Draco
Array - A set of variables

Instead of making 12 dialog button variables, you can make one dialog button "Array" and then set buttons like dialogbutton [X] where X can represent any number. Also, you'd never have to make another dialog button variable again! This is good. ;)

Much simpler and neater than lots and lots of same type variables. Use for quests and quest conditions also to be more organized!
12-06-2002, 02:24 AM#10
Ari
One function of arrays is to group many of a similar kind of variable. If for example, you wanted to keep track of the scores of all 12 players, you could have 12 variables:
player1score, player2score, etc. This would be a nightmare to keep track of though, and even worse to perform math on. Imiagine you wanted to check each player's score and award a player based on score. You'd need 12 separate if...then statements. Blech.
Instead, you create an array "playerscore." Now you do a loop
for a = 1 to 12 if playerscore[a] is > 5 display to all "player " + (integer to string (a)) + " is an elite player."

To set the variable, you simply convert the player index to the array index (that is, team 1 becomes playerscore[1] ).

This will methodically check the score of every player by checking each variable in the array. It's efficient, logical, and easier than the most brute force way of doing this.

Rather than teams, you can use a similar array system to keep track of multiple heroes.