[Solved] How to change the way Enter/OK Key works?

● ARCHIVED · READ-ONLY
Started by megumi014 6 posts View original ↗
  1. Hi, I've been trying to look the answer for this question in the forums but I always come up with answers that don't fix my problem. I don't know if it's just not possible to change it, but any advise would be helpful.

    From what I gathered when you press the Ok/Enter key it works by default as .isPressed, and I'd like it to work as .isTriggered, so it doesn't skip the text messages, mess with complicated eventing, etc.

    I fixed the eventing problem with conditionals and the Input.isTriggered('ok') script, but I still have no idea how to fix the message problem, since I don't know where the key takes the order from. I still want to use the fast-forward text option, so using a plugin to just remove it wouldn't help me.

    I also tried using Yanfly's Button Common Event plugin to override the Enter Key function but I can't find a way to make a Common Event that works for this.

    And finally I tried to look the INPUT part up on the rpg_core.js file to see if I can find a way to change the default option (this would be the ideal solution for me), but I don't know how to fix the code (my javascript knowledge is quite basic).

    Code:
    Input.isPressed = function(keyName) {
        if (this._isEscapeCompatible(keyName) && this.isPressed('escape')) {
            return true;
        } else {
            return !!this._currentState[keyName];
        }
    };
    
    Input.isTriggered = function(keyName) {
        if (this._isEscapeCompatible(keyName) && this.isTriggered('escape')) {
            return true;
        } else {
            return this._latestButton === keyName && this._pressedTime === 0;
        }
    };

    Would exchange the name of the function fix it? Or swap the return part? Or I'm in the completely wrong part of the code and I should focus on the 'keydown'? I have the feeling I would need to change more parts of the script and I don't want to mess it up.

    In short: is there a way to change the default way the enter key works? If not, anyone has any advice for the text message skip problem without giving up the fast-forward option?

    Thanks for any pointers/help you could give me.
  2. First of all, you've been looking in the wrong place. Input.isPressed and isTriggered have nothing to do with Enter.
    It has to do with pressing any key.
    isTriggered is when you just press the key, isPressed refers to the current state. There is also a third method, isLongPressed, which is when you hold a key for at least a certain amount of time.

    Where you should have looked is either default Game_Message object or a custom plugin, because how message treats the okay key is defined there. Since you're mentioning skipping messages, I presume you're using Yanfly message core and you'd be looking for Input.isLongPressed('ok') and deleting the segment of the code.
  3. Poryg said:
    First of all, you've been looking in the wrong place. Input.isPressed and isTriggered have nothing to do with Enter.
    It has to do with pressing any key.
    isTriggered is when you just press the key, isPressed refers to the current state. There is also a third method, isLongPressed, which is when you hold a key for at least a certain amount of time.

    Where you should have looked is either default Game_Message object or a custom plugin, because how message treats the okay key is defined there. Since you're mentioning skipping messages, I presume you're using Yanfly message core and you'd be looking for Input.isLongPressed('ok') and deleting the segment of the code.

    Hey, thanks for the answer but I'm still kinda stuck.
    I've been using a new project to test all the changes, so I don't take into account plugins yet.

    I couldn't find any reference to the keys anywhere on the Game_Message object ^^U But at least I found how to manage the conditional branch on the Game_Interpreter (it had a line for the buttons). In there I found a section dedicated to the Show Text action but I still can't find anything about buttons or keys in there.

    If I tried to erase the .isLongPressed but the game crashed, so I tried to change all the .isPressed/.isLongPressed in all the code for .isTriggered (as a crazy try) and the messages still flew by lol.

    I found somehow a solution changing the Input.keyRepeatWait on the Core from 24 frames to 600. I don't think it's the perfect solution but at least I can use it as a patch.

    Do you know if changing the setWaiting or something from here could be the solution?
    Code
    Code:
    Game_Interpreter.prototype.command101 = function() {
        if (!$gameMessage.isBusy()) {
            $gameMessage.setFaceImage(this._params[0], this._params[1]);
            $gameMessage.setBackground(this._params[2]);
            $gameMessage.setPositionType(this._params[3]);
            while (this.nextEventCode() === 401) {  // Text data
                this._index++;
                $gameMessage.add(this.currentCommand().parameters[0]);
            }
            switch (this.nextEventCode()) {
            case 102:  // Show Choices
                this._index++;
                this.setupChoices(this.currentCommand().parameters);
                break;
            case 103:  // Input Number
                this._index++;
                this.setupNumInput(this.currentCommand().parameters);
                break;
            case 104:  // Select Item
                this._index++;
                this.setupItemChoice(this.currentCommand().parameters);
                break;
            }
            this._index++;
            this.setWaitMode('message');
        }
        return false;
    };
  4. Welp, I don't think so. However, I'm at home now and can finally look at the game code properly. And maybe teach you a little about reverse engineering in the process.

    There are three major areas where the thing can be.
    Either Game_Message (rpg_objects.js)
    or somewhere in rpg_scenes
    or in Window_Message (rpg_windows.js).

    Looking at the code, it would be best if it had been either in Game_Message or Window_Message, because had it been in rpg_scenes, it would have needed to be defined for every scene separately, which is cost ineffective.
    Since it indeed is not in Game_Message, it is probably in Window_Message.

    In Window_Message we see a function called terminateMessage that closes the window. So now we only need to find what calls this function. We find function updateInput.
    Code:
    Window_Message.prototype.updateInput = function() {
        if (this.isAnySubWindowActive()) {
            return true;
        }
        if (this.pause) {
            if (this.isTriggered()) {
                Input.update();
                this.pause = false;
                if (!this._textState) {
                    this.terminateMessage();
                }
            }
            return true;
        }
        return false;
    };
    The if (this.isTriggered() looks as an interesting if (since we also have Input.isTriggered), so we'll search for it.
    Code:
    Window_Message.prototype.isTriggered = function() {
        return (Input.isRepeated('ok') || Input.isRepeated('cancel') ||
                TouchInput.isRepeated());
    };
    So, in the end if you want to remove the skipping, here is where it is handled. Delete the "ok" thing and you're good to go.
  5. Poryg said:
    Welp, I don't think so. However, I'm at home now and can finally look at the game code properly. And maybe teach you a little about reverse engineering in the process.

    There are three major areas where the thing can be.
    Either Game_Message (rpg_objects.js)
    or somewhere in rpg_scenes
    or in Window_Message (rpg_windows.js).

    Looking at the code, it would be best if it had been either in Game_Message or Window_Message, because had it been in rpg_scenes, it would have needed to be defined for every scene separately, which is cost ineffective.
    Since it indeed is not in Game_Message, it is probably in Window_Message.

    In Window_Message we see a function called terminateMessage that closes the window. So now we only need to find what calls this function. We find function updateInput.
    Code:
    Window_Message.prototype.updateInput = function() {
        if (this.isAnySubWindowActive()) {
            return true;
        }
        if (this.pause) {
            if (this.isTriggered()) {
                Input.update();
                this.pause = false;
                if (!this._textState) {
                    this.terminateMessage();
                }
            }
            return true;
        }
        return false;
    };
    The if (this.isTriggered() looks as an interesting if (since we also have Input.isTriggered), so we'll search for it.
    Code:
    Window_Message.prototype.isTriggered = function() {
        return (Input.isRepeated('ok') || Input.isRepeated('cancel') ||
                TouchInput.isRepeated());
    };
    So, in the end if you want to remove the skipping, here is where it is handled. Delete the "ok" thing and you're good to go.

    It finally works!

    Thank you so much, specially for taking the time to explain me the process to find it, it was really helpful and it will help me in the future if I find other problems :)
  6. 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.