- Joined
- Jul 25, 2009
- Messages
- 3,091
All right then, let's get started. I don't like to take long amounts of time to read about learning something I could learn much faster myself from experience, or from images, test maps, etc. I assume you are probably the same way.
So I'll make it quick.
1. Explanation: Arrays are based on positive integers of any value between 0 and 8191. (an integer is a solid whole number like 1 or 2) Each integer in an array is basically a copy of the variable itself. (meaning, it holds similar information) Hashtables work equally as well, but arrays are normally more efficient and accessible. In this example I show you a tid-bit of the possibilities of arrays:
2. Uses: Instead of making a variable for every player on a team, like Player1Red, Player2Blue, etc. You can just make a variable based on "Player" and give it an array. (This in my opinion is much better than a player group or Hashtables) See 3. for implementation.
3. Implementation: If you are trying to set the integers in an array with one integer for each player like I was saying above, you can do what I did in the trigger below. Setting them like this could take some time, and you can use a looping integer instead, but that won't be something I explain in this tutorial (You can see the looping integer under FAQ at the bottom of the page). Not useful to you yet? See 4.
4. Simple Uses: You could create an array variable if you didn't want to make several variables of the same type. See the trigger below for an example. It is much better than a variable for each type of damage. You can apply this to anything from Unit Groups to Special Effects for a spell.
So I'll make it quick.
1. Explanation: Arrays are based on positive integers of any value between 0 and 8191. (an integer is a solid whole number like 1 or 2) Each integer in an array is basically a copy of the variable itself. (meaning, it holds similar information) Hashtables work equally as well, but arrays are normally more efficient and accessible. In this example I show you a tid-bit of the possibilities of arrays:
-
Ultra Generic Trigger Is Generic
-
Events
- Player - Player 1 (Red) types a chat message containing -start as An exact match
- Player - Player 2 (Blue) types a chat message containing -start as An exact match
- Player - Player 3 (Teal) types a chat message containing -start as An exact match
- Player - Player 4 (Purple) types a chat message containing -start as An exact match
- Player - Player 5 (Yellow) types a chat message containing -start as An exact match
- Conditions
-
Actions
- Set Players[(Player number of (Triggering player))] = (Triggering player)
-
Events
2. Uses: Instead of making a variable for every player on a team, like Player1Red, Player2Blue, etc. You can just make a variable based on "Player" and give it an array. (This in my opinion is much better than a player group or Hashtables) See 3. for implementation.
-
The Most Generic Trigger Possible
-
Events
- Time - Elapsed game time is 0.00 seconds
- Conditions
-
Actions
- Set Players[1] = Player 1 (Red)
- Set Players[2] = Player 2 (Blue)
- Set Players[3] = Player 3 (Teal)
- Set Players[4] = Player 4 (Purple)
- Set Players[5] = Player 5 (Yellow)
- -------- VS --------
- Set Player1Red = Player 1 (Red)
- Set Player2Blue = Player 2 (Blue)
- Set Player3Teal = Player 3 (Teal)
- Set Player4Purple = Player 4 (Purple)
- Set Player5Yellow = Player 5 (Yellow)
-
Events
3. Implementation: If you are trying to set the integers in an array with one integer for each player like I was saying above, you can do what I did in the trigger below. Setting them like this could take some time, and you can use a looping integer instead, but that won't be something I explain in this tutorial (You can see the looping integer under FAQ at the bottom of the page). Not useful to you yet? See 4.
-
Generic Trigger
-
Events
- Time - Elapsed game time is 0.00 seconds
- Conditions
-
Actions
- Set Players[1] = Player 1 (Red)
- Set Players[2] = Player 2 (Blue)
- Set Players[3] = Player 3 (Teal)
- Set Players[4] = Player 4 (Purple)
- Set Players[5] = Player 5 (Yellow)
-
Events
4. Simple Uses: You could create an array variable if you didn't want to make several variables of the same type. See the trigger below for an example. It is much better than a variable for each type of damage. You can apply this to anything from Unit Groups to Special Effects for a spell.
-
More Generic Trigger
-
Events
- Time - Elapsed game time is 0.00 seconds
- Conditions
-
Actions
- Set DamageTypes[1] = Normal
- Set DamageTypes[2] = Enhanced
- Set DamageTypes[3] = Fire
- Set DamageTypes[4] = Cold
- Set DamageTypes[5] = Poison
-
Events
FAQ:
#1_____________________________________________________
Q: How can I use this aside from with players and simple stuff?
A: The possibilities are too extreme for me to describe all of them, but unit or item Custom Values could be used. One great example is from indexing systems, which you can look up in our spells section.
#2_____________________________________________________
Q: How can I loop through an array?
A: Create any looping integer function, and set it up like so. It might look a little bit complicated, but it is easy to understand if you think about it. The numbers "from 1 to 5" represent the integers of your array that you will manage. For example, if you want to loop through your array X times, the loop will be from 1 to X (or 0 to X). Keep in mind that arrays can only have an index from 0-8191, because arrays are limited to 2^13 individual indices. Generally, try to keep your index values low so you won't run into any problems. The following example will assign the variable "Players" to each player from 1 to 5. (each index of "Players" will be assigned to the corresponding player)
-
Looping Stuff
-
Events
- Time - Elapsed game time is 15.00 seconds
- Conditions
-
Actions
-
For each (Integer A) from 1 to 5, do (Actions)
-
Loop - Actions
- Set LoopInt[(Integer A)] = (Integer A)
- Set Players[LoopInt[(Integer A)]] = (Player(LoopInt[(Integer A)]))
-
Loop - Actions
-
For each (Integer A) from 1 to 5, do (Actions)
-
Events
Q: What should the array be set to?
A: The number of things you are indexing, if you are following my example of setting using Player Number of Triggering Player, you would have 1 integer for each player, which if you had 12 players, would be 12, so that's what you set the array to. Most people skip this step, and just leave it at 1, (World Editor's script adds the rest of the numbers as your triggers do), but I think you should set it like I said, to the number of things you are indexing. I stated earlier the maximum of the Array is 8191, it cannot exceed that, see FAQ #2 for more explanation on this subject.
THANKS FOR READING!
Last edited by a moderator: