Indexing takes advantage of Arrays to create multiple versions of a single variable.
So if you're ever creating multiple versions of a variable like this: Player1Hero, Player2Hero, Player3Hero, etc... you should know that using an Array would make this a MUCH easier process as you can achieve this with a single variable. It also allows you to make many shortcuts for your triggers that reference these variables.
Now here's two ways of going about creating a Unit variable that keeps track of each player's Hero (you'll see this in Arena games or games that you only control 1 Hero):
BAD METHOD:
This takes 3+ variables:
Player1Hero = player 1's hero, Player2Hero = player 2's hero, Player3Hero = player 3's hero, etc...
GOOD METHOD:
This takes 1 variable with an Array []:
PlayerHero[1] = player 1's hero, PlayerHero[2] = player 2's hero, PlayerHero[3] = player 3's hero, etc...
So the [Index] acts as it's own unique variable, meaning, if you kill PlayerHero[2] it will kill player 2's hero but not mess with the other player's heroes.
Now here's why Indexing is so useful.
Compare these two triggers, the first one uses the BAD method and the other one uses the GOOD method. This trigger will kill the Player's hero when they type -kill:
-
Bad Example
-

Events
-


Player - Player 1 (Red) types a chat message containing -kill as An exact match
-


Player - Player 2 (Blue) types a chat message containing -kill as An exact match
-


Player - Player 3 (Teal) types a chat message containing -kill as An exact match
-

Conditions
-

Actions
-


If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-



If - Conditions
-




(Triggering player) Equal to Player 1 (Red)
-



Then - Actions
-



Else - Actions
-




If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-





If - Conditions
-






(Triggering player) Equal to Player 2 (Blue)
-





Then - Actions
-





Else - Actions
-






If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-







If - Conditions
-








(Triggering player) Equal to Player 3 (Teal)
-







Then - Actions
-







Else - Actions
Now look at how much easier this one is.
Each player has a Player Number that you can reference at any given time. Player 1's number = 1, Player 2's number = 2, Player 3's number = 3, etc...
-
Good Example
-

Events
-


Player - Player 1 (Red) types a chat message containing -kill as An exact match
-


Player - Player 2 (Blue) types a chat message containing -kill as An exact match
-


Player - Player 3 (Teal) types a chat message containing -kill as An exact match
-

Conditions
-

Actions
-


Unit - Kill PlayerHero[(Player number of (Triggering player))]
So the trigger will put the player number of whoever typed -kill (1, 2, 3, etc...) inside of the Index.
Since we assigned PlayerHero[
1] to player 1's hero, and we know that Player 1's Number =
1, this will kill player 1's hero. It will also kill the correct hero for Player
2, and Player
3.
This is just one way that you can take advantage of Arrays to make your triggers more efficient.
But not every situation is that simple that you can just plug the Player's Number into the Index and have it work.
Here's that concept applied to the Charm_Buff variable:
-
Actions
-

Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\NightElf\FaerieFire\FaerieFireTarget.mdl
-

Set VariableSet Charm_Buff[1] = (Last created special effect)
-

Wait 8.00 seconds
-

Special Effect - Destroy Charm_Buff[1]
But how is this useful? Well, in it's current form it isn't useful but with some special techniques we can make this work.
So now all that's left to do is make the [Index] unique to the Charmed unit. This way each Charmed unit will have it's own Index [] for the Charm_Buff special effect.
This is where systems like these come in handy:
GUI Unit Indexer 1.4.0.0
Visualize: Dynamic Indexing
Here's our trigger from above but this time taking advantage of a Unit Indexer:
-
Unit Indexer Method
-

Events
-

Conditions
-

Actions
-


Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\NightElf\FaerieFire\FaerieFireTarget.mdl
-


Set VariableSet Charm_Buff[(Custom value of (Picked unit))] = (Last created special effect)
-


Wait 8.00 seconds
-


Special Effect - Destroy Charm_Buff[(Custom value of (Picked unit))]
The Unit Indexer assigns each unit a unique Custom Value, this is an Integer stored to the unit. No two units will ever have the same Custom Value so you'll always be putting a unique # inside the [Index] for Charm_Buff.
So with Indexing [] we can do all sorts of tricks to make this work.