Trying to track last target

Hello everyone,

this is my very first post on this forum. I'm quite new to RM and ruby so please forgive me if this question sounds dumb or this is not the right place to post such questions. I already used the search feature to look for similar questions but apparently I am not lucky (or just very bad at using that search feature...which is also quite possible).

At the moment I am trying to understand how targeting works. I was looking into Game_Battler and I found a variable called last_target_index. I feel like if I miss something obvious but I cannot understand how this variable changes. My idea was to use it to keep track of the targed so i could do something like this:

1) when last_target_index is the enemy I want to attack I store its value into another variable;

2) when my conditions are met I do something on that target using the stored value to track it.

#-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_reader :battler_name # battle graphic filename attr_reader :battler_hue # battle graphic hue attr_reader :action_times # action times attr_reader :actions # combat actions (action side) attr_reader :speed # action speed attr_reader :result # action result (target side) attr_accessor :last_target_index # last target attr_accessor :animation_id # animation ID attr_accessor :animation_mirror # animation flip horizontal flag attr_accessor :sprite_effect_type # sprite effect attr_accessor :magic_reflection # reflection flagHere is where I found this variable. Now my questions are: How does it change? How can I use it to keep track of my target?

Sorry again if my question is a dumb one but I am still new to ruby and I still have difficulties tracking everything.
I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.
I am sorry, I am still new to the forum and I wasn't able to completely understand the difference between "Support" and "Script Support" sections. Now I know it.

About my previous question: looking around for something else I aldo found the target_index variable which is probably easier to use. At the moment I have no time to test it since I am not home, so I ask here.

If b is the target of an attack and a is the caster, are target_idex value and b value the same then the skill formula is applied? If not, how do they work? How different are they in THAT specific situation? If yes, can I store a value (not b ) in a variable and use it as a target to forced actions?

Thank you all.

EDIT: what I mean is something like this:

SkillName

skill_name_formula:

v[x]=a#here goes the damage formula, not very useful for what I need at the momentthen force an action against target stored in variable v[x] previously saved.

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-track-last-target.45336/