[Solved] Plugin Command Question

Status
Not open for further replies.

megumi014

Veteran
Veteran
Joined
Mar 8, 2017
Messages
130
Reaction score
213
First Language
Spanish
Primarily Uses
RMMV
(I hope this is the right part of the forum to post this)

Hi, I'm trying to make a plugin command but nothing seems to work, I don't understand how this pluginCommand function works. I tried watching some tutorials but none are what I'm looking for:

I have this piece of code:

Code:
    Window_Message.prototype.updatePlacement = function() {
        this._positionType = $gameMessage.positionType();
        this.y = this._positionType * (Graphics.boxHeight - this.height) / 2;
        this.x = 190;
        this.width = 800;
        this.height = messageHeight; // the default is 150.
    };
this.height is the part I want to change through PluginCommand. The variable is a parameter:

Code:
var messageHeight = Number(parameters['Message Text Height']);
And this is the Plugin Command I made, but it doesn't work:

Code:
    var PEZ_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        PEZ_Game_Interpreter_pluginCommand.call(this, command, args);
        
        if(command === "MessageHeight") {
            var messageHeight = Number(args[0]);
            }       
    };
I also tried to make it without any parameter and write Window_Message.height = Number(args[0]);

When I write MessageHeight 50, nothing changes.

Any help/idea?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
It would be much more helpful to have the code in a proper order, because code snippets will not tell anything about code structure.
 

megumi014

Veteran
Veteran
Joined
Mar 8, 2017
Messages
130
Reaction score
213
First Language
Spanish
Primarily Uses
RMMV
It would be much more helpful to have the code in a proper order, because code snippets will not tell anything about code structure.
This is the part of the parameters/ plugin commands/ windows message from the plugin.

Code:
[...]
 * @param Message Text Height
 * @desc Sets the height of the message text window.
 * Default 150.
 * @default 150
[...]

(function(){

//=============================================================================
//
// 0. PARAMETERS
//
//=============================================================================  
   
    var parameters = PluginManager.parameters('PEZ_CustomGameBase');
    var messageHeight = Number(parameters['Message Text Height']);
   
//=============================================================================
//
// 0.5 PLUGIN COMMANDS
//
//=============================================================================
   
    var PEZ_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        PEZ_Game_Interpreter_pluginCommand.call(this, command, args);
       
        if(command === "MessageHeight") {
            var messageHeight = Number(args[0]);
            //Window_Message.height = Number(args[0]);
            }  
    };
   
//=============================================================================
//
// 6. WINDOW MESSAGE
//
//=============================================================================

    Window_Message.prototype.updatePlacement = function() {
        this._positionType = $gameMessage.positionType();
        this.y = this._positionType * (Graphics.boxHeight - this.height) / 2;
        this.x = 190;
        this.width = 800;
        this.height = messageHeight;
    };

})();
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
This code illustrates the problem much better.
In fact you made two mistakes.
var PEZ_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; Game_Interpreter.prototype.pluginCommand = function(command, args) { PEZ_Game_Interpreter_pluginCommand.call(this, command, args); if(command === "MessageHeight") { var messageHeight = Number(args[0]); //Window_Message.height = Number(args[0]); } };
Defining var messageHeight here is useless, because local variables are defined only in scope of the function they are called in. Meaning once you get out of the scope, it's undefined. Therefore for any other function out there it is unreachable.

However... Even
var parameters = PluginManager.parameters('PEZ_CustomGameBase'); var messageHeight = Number(parameters['Message Text Height']);
will not yield you any significant result. For the very same reason.
Everyone just wraps their plugins in a self-invoking function. I'm not sure why they do it, but what I know is that they should at least know what is the proper reason to use self-invoking functions.
The proper reason why people use them is simply to prevent any variables from becoming global. Once the self-invoking function stops resolving, any highest level variables in that function will be undefined. That's exactly what they want from self-invoking functions, one-time use variables. So since you use variables that need to maintain their value, you should delete the self-invoking function wrap and then it should work.
 

megumi014

Veteran
Veteran
Joined
Mar 8, 2017
Messages
130
Reaction score
213
First Language
Spanish
Primarily Uses
RMMV
So since you use variables that need to maintain their value, you should delete the self-invoking function wrap and then it should work.
That makes sense, you mean the (function(){})(); part, right? I usually work directly on the code, so I didn't even stop thinking about that.

Even so it still doesn't work :kaoswt2: I just made a new plugin with only this inside and turned every other plugin off.

Code:
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        
        if(command === "MessageHeight") {
            Window_Message.height = Number(args[0]);
            }     
    };


    Window_Message.prototype.updatePlacement = function() {
        this._positionType = $gameMessage.positionType();
        this.y = this._positionType * (Graphics.boxHeight - this.height) / 2;
        this.x = 190;
        this.width = 800;
        this.height = 150;
    };
I tried changing height for width but nay. I call the command with MessageHeight space and 50 [MessageHeight 50].

I feel like I'm completely missing something T_T I guess I will try again tomorrow.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Well, I completely forgot to mention that
Window_Message.height = Number(args[0]);
will not do anything either.

Window_Message is a draft for an object, so to speak. And you can't influence properties of all like that, you'd need to target a proper window...
What you can do is reference the height from a game variable though.

Code:
if(command === "MessageHeight") $gameVariables.setValue(1, Number(args[0]);

Window_Message.prototype.updatePlacement = function() {
       this._positionType = $gameMessage.positionType();
       this.y = this._positionType * (Graphics.boxHeight - this.height) / 2;
       this.x = 190;
       this.width = 800;
       this.height = $gameVariables.value(1) || Number(PluginManager.parameters('PEZ_CustomGameBase')['Message Text Height']);
   };
However, you also need to watch out for the fact that the changes will only be visible when the updatePlacement function is called.
 

megumi014

Veteran
Veteran
Joined
Mar 8, 2017
Messages
130
Reaction score
213
First Language
Spanish
Primarily Uses
RMMV
You are a life saver! Today I wanted to see if I could use the game variables to store the window height but I had no idea how to call it back or use it once stored, so you saved me from headbutting with the code for hours lol

It works perfectly now ^^ thank you very much.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,842
Reaction score
5,225
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,050
Members
137,571
Latest member
grr
Top