Different events for different characters

In my project, I would like to have an item that adds a skill point to an actor's total. I have the script call that would allow me to change an individual character's skill point total. I assigned a common event call to the item, but have run into a wall. I don't know how to have the common event differentiate between different characters.

In short: Is there a way for the engine to be able to memorize the ID of the specific actor an item is used on?
Different characters are differentiated by the $data_actors[id] variable, where "ID" is the number in the database.
Though, this is an array that contains all the data for the actor. You would further check their ID by using the id method.
So $data_actors[1].id is equal to the value "1", because it is the first actor in the database.

I'm actually not entirely sure how you would check this in an event. I would think you could iterate through each party member with a for loop, and then doing whatever based on that party member's ID, but someone else should/could correct me if I'm wrong or if there is a better way:

To do it in an event, it looks like you'd have to initialize a variable for the loop count. In this case, I used the variable with an ID of 1.

My event that checks each party member and then does something kind of looks 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
Repeat above
This sets a variable equal to the number of party members, then sets "Loop" to the value of that variable. Then it goes through and checks to see if the actor's ID is equal to the iteration of the loop we're on. So first, it'll be equal to the first actor, then the second time the loop processes, it will look at the second actor, so on and so forth.

I hope this helps and isn't too convoluted of an approach to what you're looking for. From what I can tell, there really isn't any event item that checks "What is the current actor?", but I could be wrong.
I think I understand at least the basic idea of your system, but I have a few questions.

First, I think I get what initializing a variable for the loop count means, but I have no clue how to actually do it.

Second, once I figure out how to initialize the loop count variable, I need to make it so that only the target of the item (Like how a potion only affects the party member it is used on) receives the intended effect. If the loop count is what determines which actor receives the effect, wouldn't the actor with the lowest ID always be the one affected?

If I use the item that calls the event on the actor with the ID of 2, that won't make the loop count start at 2, so the actor with the ID of 1 will always be the only one affected since the loop count can only start at 0. At least, I think it can only start at 0.

If there is a way to change the starting loop variable based on which actor the item is used on, then this would work perfectly.

I'm not the best at coding, so if I'm missing something, or I'm just wrong completely, please bear with me.
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.
Here's a screenshot of what the event looks like (I just set the final value to 4, but you would use the party size instead):

9H1pqrm.png
But if the loop count always starts at 1, then to even get to the "Do stuff" portion of 2nd 3rd or 4th party members, wouldn't the event have to run:

Code:
Conditional Branch: Script: $data_actors[$game_variables[1]].id == 1

Before it could make it to the latter actors, since at the beginning, the loop count will always be one, which is equal to the ID of the first actor? If I use an item on actor 1, the effect would work, but if I use the same item on actor 4, it seems like the event would have to loop 3 or 4 times to reach it, having the "Do stuff" portion run once for each of the party members before it.

Code:
Conditional Branch: Script: $data_actors[$game_variables[1]].id == 2

and

Code:
Conditional Branch: Script: $data_actors[$game_variables[1]].id == 3

Would have to run before

Code:
Conditional Branch: Script: $data_actors[$game_variables[1]].id == 4
But if the loop count always starts at 1, then to even get to the "Do stuff" portion of 2nd 3rd or 4th party members, wouldn't the event have to run:

Code:
Conditional Branch: Script: $data_actors[$game_variables[1]].id == 1

Before it could make it to the latter actors, since at the beginning, the loop count will always be one, which is equal to the ID of the first actor? If I use an item on actor 1, the effect would work, but if I use the same item on actor 4, it seems like the event would have to loop 3 or 4 times to reach it, having the "Do stuff" portion run once for each of the party members before it.

Code:
Conditional Branch: Script: $data_actors[$game_variables[1]].id == 2

and

Code:
Conditional Branch: Script: $data_actors[$game_variables[1]].id == 3

Would have to run before

Code:
Conditional Branch: Script: $data_actors[$game_variables[1]].id == 4
Yes, the loop will run 4 times before ending, but this processing occurs quick enough that it shouldn't impact anything.

Remember, when the condition evaluates to false, that entire block of code is completely ignored by the loop. So essentially, you are only running one block of code for each actor with this loop. The loop assures that you check each actor and do something for them, which I thought you wanted to with your item with a single common event, but I might be misunderstanding.

Do you have an example of the script you're trying to use on your actors?
The original plan was

1. Use an item that would grant an additional skill point to the actor it was used on.
2. To give an additional skill point to a specific actor, I need to use a particular script call, being
Code:
$game_actors[ID].skill_points
which only allows me to modify the skill points of one particular actor.
3. The problem being, I don't know how to splice the ID of the actor that the item was used on into that script call.
4. If I could have the ID of the actor the item was used on checked and memorized as a variable, I think I could use that "Actor ID" variable to create conditional branches such as "Actor ID = 1" or "Actor ID = 2" so that I would have a way to make sure that the actor the item was used on was the only one that received the additional skill point.

I'm sorry if I wasn't clear enough originally.
I think ultimately this is going to be something better suited for a script overall, because it looks like when you use an item with a Common Event tied to it, it will actually boot the player out of the menu and send them back to the map screen, which could get pretty aggravating for an item.

You can validate the actor ID with $data_actors[ID].id. So $game_actors[$data_actors[1].id].skill_points would run the skill_points method on the first actor in the database.

But since it's a common event call, this would bring your player to the map screen instead of remaining in the menu, I'm pretty sure.

I'll see if I can help you devise a script for this after work.
I don't really have a problem with actually using the script call. In fact, the $data_actors[ID].id is entirely unnecessary. Simply inputting the actor's database ID into the $game_actors[ID] will suffice.

The major flaw with the script call is that when it is called, it can only modify the actor whose ID is input into $game_actors[ID].

This is a problem, because I don't know how to validate only the actor ID of the party member the item was used on.

For example: I have the item that gives an additional skill point. Since I would have to call a common event to call a script, I create a common event with the
Code:
$game_actors[1].skill_points
script call. I then use that script call to modify the number of skill points actor 1 has available.

There is a problem with this. That being, no matter which party member I use the item on, the same common event will be called, and only actor 1 specifically, will gain a skill point. The goal is to make it so that if I use the item on actor 3, only actor 3 will receive a skill point, if the item is used on actor 4, actor 4 will receive the skill point, and so on.

I tried looking at how other items are handled in the base scripts, (Like how potions only heal the actor they are used on) but I have no clue as to how they work. The best I could guess is that it might have something to do with scope, but I don't know.

Original thread: https://forums.rpgmakerweb.com/threads/different-events-for-different-characters.86227/