Questions about plugin making

UniqueName

Veteran
Veteran
Joined
Nov 12, 2018
Messages
78
Reaction score
12
First Language
Russian
Primarily Uses
Other
Hello, I'm trying to make some plugins plivately for my project and I have 2 questions
1. When I try to use $game, $data or any other command that starts with "$" in my js file it throws the "cannot read property ... of null". But if I put it inside a Game_Interpreter.prototype.pluginCommand it works perfect, so I assume I can only use "$" data inside of original rpg maker function. But how can I make it so I could use it in my js file in any place I want?
2. How do I use functions from one of my js file in another? For example: I created 1 js plugin with an array and 2nd with a script that summons a window on a button. How do I make it that way so I could summon a window from 2nd js that shows data from an array from 1st js?
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
534
First Language
English
Primarily Uses
N/A
I would imagine you would need to make $Gamedata a function in your plugin. Don't quote me on that, sense i'm not a scripter. I say, come through the game interpreter and other scripts and see how they do it. But don't edit anything unless your sure of what your doing. Like changing the crit multiplyer from *3. to *2 or *1.5
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,087
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
  1. main.js loads after the base code files and is responsible for launching the game proper:
    Code:
    PluginManager.setup($plugins);
    window.onload = function() {
        SceneManager.run(Scene_Boot);
    };
    I.e. the base code files are loaded, then the plugins are added, then the boot scene starts. The database is loaded during the boot scene: $dataActors etc aren't initialised until then, so attempting to reference them when your plugin loads will result in an error. Similarly, $gameActors etc are instanced on a per-playthrough basis.

    You can alias an appropriate method and insert your code like that, e.g.
    Code:
    var _DataManager_loadDatabase = DataManager.loadDatabase;   // Remember original routine
    DataManager.loadDatabase = function() {   // loadDatabase runs once on game boot
      _DataManager_loadDatabase.call(this);   // call original routine
      // your code here
    };
    
    var _DataManager_createGameObjects = DataManager.createGameObjects;   // Remember original routine
    DataManager.createGameObjects = function() {   // createGameObjects runs on new game
        _DataManager_createGameObjects.call(this);   // call original routine
        // your code here
    };

  2. All active plugins are loaded and merged into one page, so this is a question of Scope. A common approach is to set aside a global "namespace" variable for the plugin (often as a property of an author namespace to help avoid naming conflicts) and define the plugin's public methods on that. A quick example of this:
    Code:
    // global variables to organise plugin code
    var author = author || {};   // author namespace, i.e. everything by "author" (rename as appropriate)
    author.pluginName = author.pluginName || {};   // plugin namespace, i.e. everything from this plugin
    
    (function($) {   // IIFE (optional)
      $.cake = 'cake';   // define a string property
      $.myFunc = function(a) {   // define a function
        return a + 1;
      };
    })(author.pluginName);
    Both cake and myFunc are defined on author.pluginName, which is global, so they are also global. E.g. you can use these expressions in script calls or in other plugins:
    Code:
    author.pluginName.cake
    author.pluginName.myFunc(5)
 

UniqueName

Veteran
Veteran
Joined
Nov 12, 2018
Messages
78
Reaction score
12
First Language
Russian
Primarily Uses
Other
  1. main.js loads after the base code files and is responsible for launching the game proper:
    Code:
    PluginManager.setup($plugins);
    window.onload = function() {
        SceneManager.run(Scene_Boot);
    };
    I.e. the base code files are loaded, then the plugins are added, then the boot scene starts. The database is loaded during the boot scene: $dataActors etc aren't initialised until then, so attempting to reference them when your plugin loads will result in an error. Similarly, $gameActors etc are instanced on a per-playthrough basis.

    You can alias an appropriate method and insert your code like that, e.g.
    Code:
    var _DataManager_loadDatabase = DataManager.loadDatabase;   // Remember original routine
    DataManager.loadDatabase = function() {   // loadDatabase runs once on game boot
      _DataManager_loadDatabase.call(this);   // call original routine
      // your code here
    };
    
    var _DataManager_createGameObjects = DataManager.createGameObjects;   // Remember original routine
    DataManager.createGameObjects = function() {   // createGameObjects runs on new game
        _DataManager_createGameObjects.call(this);   // call original routine
        // your code here
    };

  2. All active plugins are loaded and merged into one page, so this is a question of Scope. A common approach is to set aside a global "namespace" variable for the plugin (often as a property of an author namespace to help avoid naming conflicts) and define the plugin's public methods on that. A quick example of this:
    Code:
    // global variables to organise plugin code
    var author = author || {};   // author namespace, i.e. everything by "author" (rename as appropriate)
    author.pluginName = author.pluginName || {};   // plugin namespace, i.e. everything from this plugin
    
    (function($) {   // IIFE (optional)
      $.cake = 'cake';   // define a string property
      $.myFunc = function(a) {   // define a function
        return a + 1;
      };
    })(author.pluginName);
    Both cake and myFunc are defined on author.pluginName, which is global, so they are also global. E.g. you can use these expressions in script calls or in other plugins:
    Code:
    author.pluginName.cake
    author.pluginName.myFunc(5)
Thanks dude
One last question
In the function($) you used "$"
What exactly does this dollar sign do?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,087
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
Thanks dude
One last question
In the function($) you used "$"
What exactly does this dollar sign do?
It's the first argument of the IIFE; you can name it whatever you like but $ is a common name or prefix meaning "global variable". The brackets after the function contain the values passed to the function. So basically, inside the IIFE in my example, $ = author.pluginName. :)

I.e. this:
Code:
(function($) {
  // stuff
})(input);
Works similarly to this:
Code:
var myFunc = function($) {
  // stuff
};
myFunc(input)
Except that in the first one, the function isn't available to call later on. :kaothx:
 

UniqueName

Veteran
Veteran
Joined
Nov 12, 2018
Messages
78
Reaction score
12
First Language
Russian
Primarily Uses
Other
It's the first argument of the IIFE; you can name it whatever you like but $ is a common name or prefix meaning "global variable". The brackets after the function contain the values passed to the function. So basically, inside the IIFE in my example, $ = author.pluginName. :)

I.e. this:
Code:
(function($) {
  // stuff
})(input);
Works similarly to this:
Code:
var myFunc = function($) {
  // stuff
};
myFunc(input)
Except that in the first one, the function isn't available to call later on. :kaothx:
Thanks again dude✌
Now I've got answers to all the important questions I had the whole time
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,986
Members
137,561
Latest member
visploo100
Top