I'm trying to replace one state with another on the last targeted enemy, but for some reason my code for it won't work. Any thoughts?
Simple code question
RPG Maker MZ SupportYou're setting variable 7 to the last target enemy index. This is a number. You're then using that number as "target"; a number is not a battler, so it doesn't have the functions you're trying to call. You need to use lastTargetedEnemy as an index to $gameTroop's members.
I don't think I quite understand what I need to do, Because I tried both $gameTroop.members()[$gameVariables.value(7)] and $gameTroop.troop($gameVariables.value(7)).index(), but neither of them seem to do anything
Last Target Enemy Index is stored as 1 + the actual index, so try something like this instead:
Or, since you're already scripting most of it, just skip the variable entirely:
JavaScript:
var target = $gameTroop.members()[$gameVariables.value(7) - 1];
JavaScript:
var target = $gameTroop.members()[$gameTemp.lastActionData(5) - 1];
Thanks so much, that was the problem.
Original thread: https://forums.rpgmakerweb.com/threads/simple-code-question.178511/