[Solved] Plugin Command Question

● ARCHIVED · READ-ONLY
Started by megumi014 8 posts View original ↗
  1. (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?
  2. It would be much more helpful to have the code in a proper order, because code snippets will not tell anything about code structure.
  3. Poryg said:
    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;
        };
    
    })();
  4. This code illustrates the problem much better.
    In fact you made two mistakes.
    megumi014 said:
    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
    megumi014 said:
    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.
  5. Poryg said:
    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.
  6. 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.
  7. 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.
  8. 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.