Questions about plugin making

UniqueName

Veteran
Veteran
Joined
Nov 12, 2018
Messages
76
Reaction score
10
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
531
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,044
Reaction score
1,474
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
76
Reaction score
10
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,044
Reaction score
1,474
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
76
Reaction score
10
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

Lately when I listen to 1970s songs, I always think that the "real world" is still at mid 70s. What we experience now is a futuristic dream. With this point of view, even 80s and 90s looks super futuristic. :D

The GIF of this seemed too cool to bury in replies. :LZSwink:
You may have slept with my aunt... but, given the circumstances, cheers.

- Professor Ian Duncan, 2013
Ami
--- Swimming ---

F.Knight: This Shrine always Flood. We don't have a choice,we have to Swimming in this place
F.Healer: That Insane!
F.Mage: We can use…Boat,rather than Swimming
F.Knight: You guys…Can't Swim?
F.Healer & F.Mage: (Shocked) Eehh??

Forum statistics

Threads
105,525
Messages
1,014,391
Members
137,209
Latest member
RowanWolf
Top