targeting force action based on variable.

I've been trying to make something where an Actor attacks a target automatically, with the specific target determined by a variable. However, I can't figure out how to actually make that work.

I tried doing
Code:
$game_actors[1].force_action(335,$game_variables[221])
(all these numbers are just examples by the way, none are the number that would actually be used in the finished version), but that just didn't do anything.

An acquaintance of mine who is a fairly skilled RPG Maker VX Ace script maker told me almost explicitly that this was how it worked, but it just doesn't. The only difference between my test and his example is the number for the action performed and variable that tells the game what enemy to target. Does anybody know how to actually make it work?

Edit: Nevermind, it just interacted wonkily with 'end of turn' troop events.
told me almost explicitly that this was how it worked
That would be true for the method. def force_action(skill_id, target_index)
But where are you putting the code? That method is in Game_Battler so it should reach it from Game_Actors, but you should use game_actor[1]
Ruby scripters correct me if I'm a little off.

Is that actor in the party and in the battle?
Sorry for wasting your time, I found the problem. It just doesn't like it when you have the common event that triggers it activated by an 'end of turn' troop event. Setting it to trigger every 1*x turns fixed the whole issue.
Sorry for wasting your time, I found the problem. It just doesn't like it when you have the common event that triggers it activated by an 'end of turn' troop event. Setting it to trigger every 1*x turns fixed the whole issue.
Worth to remember that the 'end of turn' trigger loops, so you have to put a command to stop event at the end of everything.

Original thread: https://forums.rpgmakerweb.com/threads/targeting-force-action-based-on-variable.129805/