Programming Plugins Tutorial
This is a basic overview of how to write plugins in RPG Maker MV. It will continually be improved upon, adding more details.
Make sure to read JS Basics on my blog before diving in if you have no idea how to program. it will help get your feet wet.
Go here to understand the API of pixi.js the framework that RPG Maker uses for its JS renderer.
http://pixijs.github.io/docs/
1. Define parameters. The first bit "Default 0" is the text that is shown in the Plugin Manager, the 2nd bit is the actual parameter value that is set. 0 or 1 equals false or true, too.
* @param Max Resolution Height
* @desc The max height you want your game to have.
* Default: 0
* @default 0
2. Create a global namespace, which is your global identifier for the class. A class being what holds all your functions and code aka the template. Do not use .js at the end of NAMEOFPLUGIN and make sure to replace NAMESPACE with the name of your identifier such as your name or custom plugin/framework name.
NAMESPACE.Parameters = PluginManager.parameters('NAMEOFPLUGIN');
NAMESPACE.Param = NAMESPACE.Param || {};
3. Set your parameter. Replace PARAM with the name of the parameter you want to call it. 0 is the default value it will load if it is not loaded properly for whatever reason.
Code:
NAMESPACE.Param.PARAM = eval(String(NAMESPACE.Parameters['PARAM'] || "0"));
You can test your parameter value by using something like this. If you check for these you do not have to check if they are 0 or 1; you can simply check if they are true or false using a typical if statement. By default the statement will check for a true or false based on the variable that is specified.
if (NAMESPACE.Param.PARAM)
{
// Do work here.
}
4. Define any custom functions you want. You can either extend a function or override it. It is suggested to not override where possible. Overridding a function means any code that was defined previously to your plugin (in ascending order - any that are above will not be called). Where if you extend a function, it will keep all the previous code that has been called.
To override a function simply copy the function entirely and change it how you see fit. make sure to place the override function below the function you want to override.
To extend a function you have to set the function to a variable or object, this allows you to duplicate the function code in another instance to be called again. You then have to call that instanced function using that variable or object inside the function.
Helladen.ScrRes.SceneManager_run = SceneManager.run;
SceneManager.run = function(sceneClass) {
Helladen.ScrRes.SceneManager_run.call(this, sceneClass);
}
5. Create your custom logic now. Use the basic principles that I have shown you to do that. You can create additional functions and use those inside the functions you either override or extend. This is how you expand the codebase.
Use this code to debug. You can specify entire objects then break them open inside the log window. To open this window up, simply press F8.
Code:
console.log("Hello World.");
If you would like me to continue expanding this tutorial, reply here with what you need help with learning.
本贴来自国际rpgmaker官方论坛作者:Helladen处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/programming-plugins-tutorial.66514/