I'm writing an if statement that will depend on the value of an Enemy's TP, but I can't figure out the script for returning it. I've tried the code used in a thread I thought was the exact same as my situation, $gameTroop.members()[1].tp and $gameTroop.members()[0].tp0, but neither are working. Do they just not apply to an if statement, or is the syntax wrong?
If statement checking Enemy TP?
RPG Maker MV SupportTP is stored on Game_Enemy instances as _tp. Try referencing ._tp instead of .tp
I used "$gameTroop.members()[0]._tp "and it's coming up with an error: "Unexpected Token ." That same error comes up for .tp, [1] (in case it doesn't start the array with 0), and they don't work. Using just "_tp" comes up with a different error.
Can you show us a screenshot of your event where you're making the script call? That should be a valid line of JavaScript to execute. Here's what I get when executing it in the developer console during a battle test:
It'll work the same either way, the data variable is "._tp" but ".tp" is a getter that just returns _tp. It's defined on Game_BattlerBase so it's inherited by both Game_Enemy and Game_Actor.
Agreed, let's see the entire event because that means there's something else going on.
Is it because I'm using an if statement underneath a pre-programmed conditional branch?
Also, when I used just "_tp" the error is "Syntax Error - Unexpected identifier"
Also, when I used just "_tp" the error is "Syntax Error - Unexpected identifier"
I guess you are trying to compare "greater than or equal to"?
You currently have it written as:
"Greater than or equal" to should be written with the greater than symbol first and then the equal symbol
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators
You currently have it written as:
Code:
=>
"Greater than or equal" to should be written with the greater than symbol first and then the equal symbol
Code:
>=
Oops, haha thank you. It works now! Also for anyone reading this, the number in the brackets did have to be 0 instead of 1 to account for the first Enemy in the Troop.
Original thread: https://forums.rpgmakerweb.com/threads/if-statement-checking-enemy-tp.104313/