What you may need to know about MV as a scripter.

● ARCHIVED · READ-ONLY
Started by Ramiro 5 posts View original ↗
  1. Hello, I started to note, a common list of things than people are having when they import your plugin inside their game,

    many of you may already have actually had to battle with this probles without knowing why it doesn't work.

    Here I'll compile an entire list of those so common bugs, and how to avoid them, or to check:

    When testing the game, remember to press F8 to open the console, that is actually the only and best way you have to debug it properly on your MV editor.

    Parameters doesn't work, my plugin breaks with no reason or says things like undefined "MyPluginName"

    This problem happens when the user renames your script as another name, so they plugin manager can't load the parameters properly.

    • As a recommendation, name your plugins like a javascript identifier: /[A-Za-z_][A-Za-z0-9_]*\.js/Why?
    People actually are doing that, so it's just to keep consistency

    • Add a little snippet if your plugin uses parameters:
    if(!Object.keys(PluginManager.parameters('MyScriptName')).length) {    throw new Error("It seems than you named 'MyPluginName' differently, this plugin won't work that way!");}You cal also use this function:

    function isEmpty (obj) { for (var k in obj) if (obj.hasOwnProperty(k)) return false; return true;}
    • Why?
    This will prevent your plugin for crashing the game, so it's quite usefull and people will know why it doesn't work!

    My plugin requires another, how do I manage that?

    The Imported variable was added only for that idea:

    if (!Imported["MyDependency"]) { throw new Error("The plugin 'MyPluginNames' requires 'MyDependency' plugin to work!");}That's why it's usefull.

    If you are using MVCommons, you can also check using:

    PluginManager.imported(string key)Even when both do the same, this one may be more easy to understand sometimes.

    Note:

    As I found more common bugs, I'll post here how to give a better information to users about them, so we can (hopefully) reduce the amount of bug reports that way.
  2. if (!PluginManager.parameters('MyScriptName')) {    throw new Error("It seems than you named 'MyPluginName' differently, this plugin won't work that way!");}
    This won't work. PluginManager.parameters() falls back to returning an empty object if it can't find the plugin. Empty objects aren't considered falsy and thus your error will never get thrown. What you could do is:

    if(!PluginManager.parameters('MyScriptName').keys.length == 0) {...}This might break your game in IE8 or lower, though, so you might fallback to a different method:
    Code:
    var isEmpty = function(object) {    for(var a in object) {        return false;    }    return true;}; if(isEmpty(PluginManager.parameters('MyScriptName'))) {...}
    A better solution (in my opinion) is using a different method for retrieving plugin parameter, like this small (and currently untested, so beware) snippet, which allows to define a plugin id in @plugindesc: http://pastebin.com/zSCKKBsE/edit: If modified, that script could actually render the whole Imported variable unneeded and register plugins by their plugin id. I wouldn't do this (at least not in the same script), since my Addon wasn't meant to be used as a needed dependency.
  3. Iavra said:
    This won't work. PluginManager.parameters() falls back to returning an empty object if it can't find the plugin. Empty objects aren't considered falsy and thus your error will never get thrown. What you could do is:

    if(!PluginManager.parameters('MyScriptName').keys.length == 0) {...}This might break your game in IE8 or lower...
    This doesn't, and it has IE9+ support:

    if(!Object.keys(PluginManager.parameters('MyScriptName')).length) { ... }My bad.. but anyway.. fixed... thanks for the bugfix
  4. One of the things you need to know is how to trace logic through undocumented core scripts. This allows you to then figure out how things are implemented
  5. It's generally good practice to take a look at VX Ace when trying to understand how certain things work in MV. The implementation is sometimes different, but they kept the general structure of the engine and most of the names are still the same.