Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

[Scripting] - How to call a plugin command in script

Status
Not open for further replies.

Starbird

Praised Adventurer
Resource Team
Xy$
0.38
I'm using Darkkitten's text input plugin and I would like to be able to pass it arguments directly from a script instead of eventing the plugin command.

Does anyone happen to know how to call a plugin command via javascript?
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Could I second this, I've been looking around $gameInterpreter for this.
I believe Game_Interpreter does not need the global var $gameInterpreter because it specifically handles event commands, so when you use a script call it's local to the Game_Interpreter class. I have never tried using the plugin command function inside a script call before but logically it should be as simple as doing any script call, depending on plugin of course.

Thisi s the main function here, and it is aliased over and over again with each plugin that uses it.
JavaScript:
Game_Interpreter.prototype.pluginCommand = function(command, args) {
    // to be overridden by plugins
};
so something like this would make sense. Right? I'd assume so lol
JavaScript:
this.pluginCommand(command, arguments);
So if you want to use plugin command as a script call try this format with the plugins command, whatever that may be nd fill in the arguments properly. In order to fil in the arguments properly you will need to take a look at how the event command 'Plugin Command" works.

JavaScript:
// Plugin Command
Game_Interpreter.prototype.command356 = function() {
    var args = this._params[0].split(" ");
    var command = args.shift();
    this.pluginCommand(command, args);
    return true;
};
As you can see above it puts a full string into the args variable then splits it with a space, so you will need to do the same format if you want to do a script call instead of the actual plugin command. I did an example of my Window Pop plugin below.

This is the script call I could use for my Window Pop plugin instead of the plugin command it provides.
JavaScript:
var args = 'WPOP left 18 Hello'.split(" ");
var command = args.shift();
this.pluginCommand(command, args);
I hope this helps you out a bit.
Alternatively you could make it shorter without the variables and do something like this.
JavaScript:
this.pluginCommand('WPOP', 'left 18 Hello'.split(" "));
 
Last edited:
Okay, I don't get you're example.

What is the command and what are the arguments?

For example if I want to send the command "StopPlayerMovement" in order to stop stuff in Yanfly's script... how do I do it. All I'm getting at the moment is undefined.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Make sure it is all in string format so use the quotes ' ' or " ". The command is the main command that the plugin uses, it will vary for all plugins, so for Yanfly StopMovment plugin they only use a command and no arguments, so I'd assume something like this would work.

JavaScript:
this.pluginCommand('StopEventMovement');
So basically to script call a plugin command relies heavily on how the author of the plugin handles thier own commands, you may have to look at how they're done but this method does work.

JavaScript:
//=============================================================================
// Game_Interpreter
//=============================================================================

Yanfly.Stop.Game_Interpreter_pluginCommand =
    Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
  Yanfly.Stop.Game_Interpreter_pluginCommand.call(this, command, args)
  if (command === 'StopEventMovement') $gameTemp.stopMapEventMovement();
  if (command === 'AllowEventMovement') $gameTemp.allowMapEventMovement();
  if (command === 'StopPlayerMovement') $gameTemp.stopMapPlayerMovement();
  if (command === 'AllowPlayerMovement') $gameTemp.allowMapPlayerMovement();
};
This is the code directly from yanflys plugin and as you can see it's only using the command argument and no args. So you only have to worry about the command part of the plugin command script call.
 
Maybe I'm an idiot (most probably) however this is my issue:

Got this on my map:


This is that plugin:

This is the console. The function commandTest is running, note the 'here'. However just after it's saying on the screen:
undefined is not a function and this:
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Okay, you're trying to call a game interperter method when out of scope. You can only call this.pluginCommand if you are inside the Game_Interpreter class. Calling this.pluginCommand(); as an actual script call inside the event will work okay because all event commands are handled by the Game_Interpreter. If you want to make your own function outside of the Game_Interpreter scope then you will have to define a global variable and assign it to Game_Interpreter. So something like this should work if this is the way you want to go about things.

JavaScript:
var $gameInterp = new Game_Interpreter();
function commandTest() {
  $gameInterp.pluginCommand('StopPlayerMovement');
}
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
I like where you're going with this, I may utilize something like this myself. I'm glad I could help, if you get any more questions I'll do my best to answer for you. Happy scripting!
 

Starbird

Praised Adventurer
Resource Team
Xy$
0.38
I like where you're going with this, I may utilize something like this myself. I'm glad I could help, if you get any more questions I'll do my best to answer for you. Happy scripting!
LTN, just wanted to drop a quick note to say that this thread explained SO MUCH to me about how RMMV is working internally. I searched for two days and couldn't find this info -- thank you so so much! I owe ya one, seriously.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
I'm glad I could help you out, I know it took me a long time to figure out how RMMV works internally and I'm still learning a lot so any chance I get to help others from pulling their hair out I do it lol. Of you have any more questions while learning feel free to make a support topic and tag me. If I can help I'll let you know. Cheers.
 
Status
Not open for further replies.
Top