UniqueName

Veteran
Veteran
Joined
Nov 12, 2018
Messages
83
Reaction score
13
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,968
Reaction score
560
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,412
Reaction score
1,822
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
83
Reaction score
13
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,412
Reaction score
1,822
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
83
Reaction score
13
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
 

Latest Profile Posts

I wish I can work faster on my game. But I don't want to get burned out. :(
I've been working on something on and off for a few years now, and I've been reluctant to share any details on the project before I had anything playable because I did not want to generate hype only for the project to go back on hiatus. That being said I believe what I'm working on is very unique and pushes the boundaries of what RPG Maker projects can be. Bold claims, I know but just wait.
Happy Mother's Day to all the moms :)
Create Anime Art w/ AI, Tall Sprites with Aurora, Customize Variable Display | RPG Maker News #34

[My favorite slow moving track I've made so far]

Forum statistics

Threads
111,196
Messages
1,059,201
Members
144,446
Latest member
ryu12582
Top