MV Update on a double press sprint code.

I decided to make a new post because I generated a new code that works.... Kind of....


JavaScript:
/*:
* @plugindesc -
* @author -
*
* @param KeyPressTime
* @desc The time in ms to register a double press. Default: 250
* @default 250
*
* @param SprintSpeed
* @desc The speed increase when sprinting. Default: 1
* @default 1
*
* @help
*/

var Imported = Imported || {};
Imported.DoublePressSprint = true;

var DoublePressSprint = DoublePressSprint || {};
DoublePressSprint.keyPressTime = Number(PluginManager.parameters('DoublePressSprint')['KeyPressTime'] || 250);
DoublePressSprint.sprintSpeed = Number(PluginManager.parameters('DoublePressSprint')['SprintSpeed'] || 1);

// Override the default moveByInput function
DoublePressSprint.moveByInput = Game_Player.prototype.moveByInput;
Game_Player.prototype.moveByInput = function() {
    if (Input.isTriggered('up') && DoublePressSprint.checkDoublePress('up')) {
        this.setMoveSpeed(this._moveSpeed + DoublePressSprint.sprintSpeed);
    } else if (Input.isTriggered('left') && DoublePressSprint.checkDoublePress('left')) {
        this.setMoveSpeed(this._moveSpeed + DoublePressSprint.sprintSpeed);
    } else if (Input.isTriggered('down') && DoublePressSprint.checkDoublePress('down')) {
        this.setMoveSpeed(this._moveSpeed + DoublePressSprint.sprintSpeed);
    } else if (Input.isTriggered('right') && DoublePressSprint.checkDoublePress('right')) {
        this.setMoveSpeed(this._moveSpeed + DoublePressSprint.sprintSpeed);
    } else {
        // call the original moveByInput function
        DoublePressSprint.moveByInput.call(this);
    }
};

// check if the specified key has been pressed twice within the specified time
DoublePressSprint.checkDoublePress = function(key) {
    var currentTime = new Date().getTime();
    if (DoublePressSprint.lastKeyPressTime[key] === undefined) {
        DoublePressSprint.lastKeyPressTime[key] = currentTime;
        return false;
    } else if (currentTime - DoublePressSprint.lastKeyPressTime[key] < DoublePressSprint.keyPressTime) {
        DoublePressSprint.lastKeyPressTime[key] = undefined;
        return true;
    } else {
        DoublePressSprint.lastKeyPressTime[key] = currentTime;
        return false;
    }
};

DoublePressSprint.lastKeyPressTime = {};

The issue with this code is that the sprint doesn't stop and go back to walking when the character stops moving and the character keeps getting faster and faster until they're sonic. Is there anything I'm missing; I'm not that code savvy like all of y'all. Tell me what snippets I need to add because I don't know what to add to resolve this issue hahah.
It would have been better for you to post this in your existing thread. People just clicking on this won't know what you're talking about, or what you're trying to achieve with this plugin.

Your character doesn't go back to their original speed because...you never tell them to 😛 After you check for dashing in all of the directions, you call the original moveByInput() function, but nothing in there sets movement speed.

You need to add a line before that to setMoveSpeed to whatever you want your default to be.
It would have been better for you to post this in your existing thread. People just clicking on this won't know what you're talking about, or what you're trying to achieve with this plugin.

Your character doesn't go back to their original speed because...you never tell them to 😛 After you check for dashing in all of the directions, you call the original moveByInput() function, but nothing in there sets movement speed.

You need to add a line before that to setMoveSpeed to whatever you want your default to be.
Ah sorry; I thought it would be better since it was different code. Sorry I'm quite new here hahah.
It would have been better for you to post this in your existing thread. People just clicking on this won't know what you're talking about, or what you're trying to achieve with this plugin.

Your character doesn't go back to their original speed because...you never tell them to 😛 After you check for dashing in all of the directions, you call the original moveByInput() function, but nothing in there sets movement speed.

You need to add a line before that to setMoveSpeed to whatever you want your default to be.
I'm kind of having difficulties following where you going with this post. I understand I didn't tell the original speed but I don't know how to add the setMoveSpeed command before the moveByInput command without ruining the code.

Original thread: https://forums.rpgmakerweb.com/threads/update-on-a-double-press-sprint-code.153957/