If you just replace TabPartyIndex with i you would always target the same player.
For the increasing loop:
i is always 1, 2, 3, 4 and then 5.
We always want the next possible partymember as a target.
Example:
We used this button a few times and now TabPartyIndex is 3.
First iteration: i=1, TabPartyIndex=4, if Party4 exists we stop
Second iteration: i=2, TabPartyIndex=5, Player exists always so we stop
If we use the button again it is time for the modulo trick
First iteration: i=1, TabPartyIndex = 5%5 + 1 = 0+1 = 1, if Party1 exists we stop
else we continue with TabPartyIndex=2 etc.
With this method we can use both buttons to cycle back and forth through the group.
|