Oh, goodness, I forgot to increment "Loop" by one each time. That's important, so it should look actually like this:
Code:
Control Variables: 0002: Party Members = Party Members
Control Variables: 0001: Loop = 1
Loop
Conditional Branch: Script: $data_actors[$game_variables[1]].id == 1
Do stuff for me, I'm the first actor
Branch End
Conditional Branch: Script: $data_actors[$game_variables[1]].id == 2
Do stuff for me, I'm the second actor
Branch End
Conditional Branch: Variable [0001: Loop] >= Variable 0002: Party Members
Break Loop
Branch End
Control Variables: 0001: Loop += 1
Repeat above
Buckle up, we're going to code school! Let's talk about FOR loops.
https://www.tutorialspoint.com/ruby/ruby_loops.htm has some information as well.
I built the loop count off of the principle of a "for" loop. It essentially looks like this:
for [variable] in [start]..[end]
do this
end
A FOR loop keeps executing until the [variable] becomes equal to the [end] value. So in a script you'd see something like this:
Code:
for i in 1..5
do something
end
The loop will run 5 times. Each time, "i" will increment by 1. This is in an iteration.
So, the first time the loop runs, i = 1, then the second time i = 2, the third time, i = 3... etc. When it reaches the [end] value, the loop stops running.
First, I initialized a variable that holds the party members size. This will help you in the future if you decide to have a party with more than 4 characters in it. This will be our [end] value:
Code:
Control Variables: 0001: Party Members = Party Member
I tried to recreate this principle using the events. So the "Loop" variable is our "i" or [variable]:
Code:
Control Variables: 0001: Loop = 1
Because the event system doesn't understand that "Loop" needs to be increased by 1 each time (a for loop does it automatically), we have to manually do it:
Code:
Control Variables: 0001: Loop += 1
Now for the conditional branches, let's break it down.
The first time the loop runs, "Loop" will = 1
So:
Code:
Conditional Branch: Script: $data_actors[$game_variables[1]].id == 1
Do stuff for me, I'm the first actor
Branch End
$game_variables[1] is actually just the script way of putting in the value of "Control Variables: 0001". Because this is "Loop" and "Loop" is equal to 1, $game_variables[1] = 1
So we have a conditional branch that checks this: $data_actors[1].id == 1
Is the 1st actor's ID equal to 1? If it is, then we're going to do stuff that applies to the first actor in our party.
The "Loop" variable is still = 1, so when it gets to this branch:
Code:
Conditional Branch: Script: $data_actors[$game_variables[1]].id == 2
Do stuff for me, I'm the second actor
Branch End
Well, $data_actors[1].id == 2 is false. It's the first ID, not the second one, so this code won't execute.
Then, at the end of the loop, we increment "Loop" by one:
Code:
Control Variables: 0001: Loop += 1
When it runs again, $data_actor[2].id == 1 is false. So the code for the first actor won't run.
But if we go back to
Code:
Conditional Branch: Script: $data_actors[$game_variables[2]].id == 2
Do stuff for me, I'm the first actor
Branch End
Now it's true! So the second actor stuff will run.
Finally, we need a way to break out of the loop:
Code:
Conditional Branch: Variable [0001: Loop] >= Variable 0002: Party Members
Break Loop
Branch End
As soon as "Loop" becomes greater than or equal to the number of Party Members (4), it will stop running.
So you can use this loop to do stuff for each specific actor in the party by just creating a new conditional branch for each one.
If you want to check the 4th actor in the party, you would just put:
Code:
Conditional Branch: Script: $data_actors[$game_variables[$game_variables[1]].id == 4
Do stuff for me, I'm the fourth actor
Branch End
Wew! I hope this explains some stuff. So basically, if you only wanted to use an item on the 4th actor, you would put your events for that item in "Do stuff for me, I'm the fourth actor". I'll get a screenshot of the event for you, so it helps.