Yanfly's 'battler' script calls.

Edit:
I figured out a way to make this work so the thread can be considered closed I suppose if the mods would like.



Hey there all, I've really been hitting a wall with this one due to my lack of javascript knowledge. I've tried countless things and had zero luck so I thought I would bug the community🙂. I have tested this on a brand new and updated project with only Yanfly's skill Mastery Levels plugin, no others, to test the code but the "battler." script call is in many of Yanfly's plugins and it does not work for me in any of them so I believe I may need to add some sort of extra js. to make it work right.

So for instance, I am trying to use, from the skill Mastery Levels plugin the Script call: battler.skillMasteryLevel(skillId).

However, in the debug console I get the code:
ReferenceError: battler is not defined.

The main way I have been trying to use this is as part of a control variable, from a common event. I assign battler.skillMasteryLevel(350) to a variable but when that variable is accessed the error is thrown. This is used as part of a skill in battle.

This error is returned with any script call that references battler. in any Yanfly script that uses that, which there are many. Yanfly always has this in the description: 'battler' is a variable that represents an actor/enemy. So I am thinking I may need to define the variable in a js. somehow but I am not sure.

I would love to hear if anyone has any ideas on this. If I need to add any info please let me know, I will happy do so. And a huge thank you for taking the time to have a look.🙂

Yanflys Skill plugin. http://yanfly.moe/2019/01/25/yep-178-skill-mastery-levels-rpg-maker-mv/
Spoiler: Full error code.
CONTROL VARIABLE SCRIPT ERROR
js/plugins/YEP_MoveRouteCore.js:1065 battler.skillMasteryLevel(350)
js/plugins/YEP_MoveRouteCore.js:1066 ReferenceError: battler is not defined
at eval (eval at Game_Interpreter.command122 (js/plugins/YEP_CoreEngine.js:1836), <anonymous>:1:1)
at Game_Interpreter.command122 (js/plugins/YEP_CoreEngine.js:1836)
at Game_Interpreter.executeCommand (rpg_objects.js:8930)
at Game_Interpreter.update (rpg_objects.js:8838)
at Game_Troop.updateInterpreter (rpg_objects.js:5226)
at Function.BattleManager.updateEventMain (rpg_managers.js:2281)
at Function.BattleManager.updateEvent (js/plugins/YEP_BattleEngineCore.js:1937)
at Function.BattleManager.update (js/plugins/YEP_BattleEngineCore.js:1895)
at Scene_Battle.updateBattleProcess (rpg_scenes.js:2265)
at Scene_Battle.update (rpg_scenes.js:2257)
Replace battler with either user, or target. Or, if you want to be more specific with actors, you can use $gameActors.actor(id). Just replace id with the ID of the actor you want to refer too.

There are a lot of ways to reference a battler beyond the examples I just gave. But those are the basics.
Replace battler with either user, or target. Or, if you want to be more specific with actors, you can use $gameActors.actor(id). Just replace id with the ID of the actor you want to refer too.

There are a lot of ways to reference a battler beyond the examples I just gave. But those are the basics.

Hey there and thank you very much for the speedy reply🙂. User is what I need but I've tried that one before and I did just recheck but it, and target, each give me the same exact error except battler is replaced by user and so on. I need it to set the variable to the actors skill mastery level who cast it but there are a lot of actors that can do it so user would be perfect if it worked.

Edit:
I just tried this on a new project, 1.6.2, with only the one plugin and user still throws the is not defined error. It seems like the game should be able to understand those commands but they are crashing the game on a fresh project. Any idea what would cause that?

Also, $gameActors.actor(id) does in fact work so the code does work but it doesn't do quite what I need.

Edit 2:
To make things a little stranger I checked other skills I have that have the user reference and they work fine. So when its coming from a skills note window the user tag works. The one that doesn't work is in the common events section if that means anything. The common event is blank except for the control variable where it sets it through the script call section. Can things like user not be referenced through a variable in this way by chance?

Edit 3:
So, after some more testing none of the user, battler tag types work within a control variable, possibly because they themselves reference a variable? With user.skillMasteryLevel(350) it is supposed to return the users mastery level for the specific skill, in this case skill id 350. What I need is to assign that number it returns to a variable. So if the actor that uses 350 has a skill level of 2 with that skill it would return a 2. My end goal is to heal the party for the amount of the skill level every turn. So in this case it would heal the group for 2 hp per turn.

Does anyone happen to know of a way to do this without using a control variable command? I think I would need some sort of script for the note section of that skill that can assign the data returned to a variable. Otherwise I don't even see how a code like user.skillMasteryLevel(350) is meant to be used in a way that you can access the number it returns.

I think I need something like this: $gameVarables.setValue(550, user.skillMasteryLevel(350)); to set variable 550 to the data but that isn't working so far.

Sorry to be a pain I really am trying to figure this out on my own I've just put so many days into trying to figure this out now that I am starting to go a little nuts.🙂
I know you've said this is solved but for the sake of anyone reading with a similar issue.

You've mentioned skills so the way to refer to the user in the damage formula is with "a" eg

Code:
a.skillMasteryLevel(350)

$gameVariables.setValue(x, a.skillMasteryLevel(350)
//example use for setting a variable to user's skill mastery level from damage formula

You've also mentioned using event commands so I assume you've got the skill calling a common event. Common events don't know who the user of a skill is because they can be called anywhere and don't take in any information. To get this information across to the common event from a skill you can set a variable using the damage formula to hold the user's actor id:

Code:
$gameVariables.setValue(x, a.actorId())

Now from your common event you can designate event commands for actors using variables. If you need to use scripts within the common event you can as well by referencing the actor like so

Code:
$gameActors.actor($gameVariables.value(x))

$gameActors.actor($gameVariables.value(x)).skillMasteryLevel(350)
//example for returning the skill Mastery Level

In all the above examples replace x with the variable you are using to store and retrieve data.

EDIT: The reason that Yanfly's script examples reference 'battler' is that they can be used on both actors and enemies, which means the scripts will work if you replace battler with any method of retrieving an actor or enemy such as

Code:
a
b
$gameActors.actor(x)
$gameParty.leader()
$gameTroop.members()[1]

Yanfly also makes provisions for the use of the word 'user'/'target' etc in some of the custom notetag evals or plugin parameters. However, there is no need for these within the damage formula themselves as 'a' and 'b' already exist.

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-battler-script-calls.108172/