MZ Need help with a conflict when patching realMoveSpeed

EDIT/correction: even when MPP_MapLight.js is turned, off, upon trying to move the player seemingly disappears.

EDIT 2: solved by replacing calling of the original function by the contents of the original function... am confused as to why, perhaps there was another overwrite somewhere that it conflicted with, but it works.


I am working on a plugin to switch map sprites (motions, like climbing or crawling) depending on the region/tag the sprite happens to be on. The changing of sprites seems to work, so as a next step I want to tweak the move speed and the stepping speed when the character is using a different motion. The stepping speed goes okay:

JavaScript:
//adjust stepping speed per motion
var CnD_CharacterBase_animationWait = Game_CharacterBase.prototype.animationWait;
Game_CharacterBase.prototype.animationWait = function() {
    const _Tag = this.terrainTag();
    if (_Tag === pMotionCrawlTerrain && pMotionCrawlTerrain > 0){
        return (9 - this.realMoveSpeed()) * 3/pMotionCrawlStep;
    } else {
        CnD_CharacterBase_animationWait.apply(this,arguments);
    }
};

but upon changing the move speed, a conflict occurs with MPP_MapLight.js:

JavaScript:
//adjust walking speed per motion
var CnD_CharacterBase_realMoveSpeed = Game_CharacterBase.prototype.realMoveSpeed;
Game_CharacterBase.prototype.realMoveSpeed = function() {
    const _Tag = this.terrainTag();
    if (_Tag === pMotionCrawlTerrain && pMotionCrawlTerrain > 0){
        return this._moveSpeed + (this.isDashing() ? 1 : 0) - (4 - pMotionCrawlSpeed);
    } else {
        CnD_CharacterBase_realMoveSpeed.apply(this,arguments);
    }
};

Error
Uncaught TypeError: Failed to execute 'createRadialGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite.

Spoiler: Console Screenshot
1730708035508.png

Spoiler: What the Console Says
DevTools failed to load SourceMap: Could not load content for chrome-extension://njgcanhfjdabfmnlmpmdedalocpafnhl/js/libs/pixi.js.map: System error: net::ERR_FILE_NOT_FOUND
rmmz_managers.js:1974 Uncaught TypeError: Failed to execute 'createRadialGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite.
SceneManager.onError @ rmmz_managers.js:1974
rmmz_managers.js:1975 chrome-extension://njgcanhfjdabfmnlmpmdedalocpafnhl/js/plugins/MPP_MapLight.js 1155
SceneManager.onError @ rmmz_managers.js:1975
MPP_MapLight.js:1155 Uncaught TypeError: Failed to execute 'createRadialGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite.
at DarknessLayer.paintNormalMapLight (MPP_MapLight.js:1155)
at Tilemap._paintLayerLights (MPP_MapLight.js:1019)
at Tilemap._paintDarknessLayer (MPP_MapLight.js:1002)
at Tilemap.updateTransform (MPP_MapLight.js:965)
at Tilemap.updateTransform (TF_LayeredMap.js:386)
at Sprite.Container.updateTransform (pixi.js:8168)
at Spriteset_Map.Container.updateTransform (pixi.js:8168)
at Scene_Map.Container.updateTransform (pixi.js:8168)
at Renderer.render (pixi.js:22057)
at Application.render (pixi.js:23257)
DarknessLayer.paintNormalMapLight @ MPP_MapLight.js:1155
Tilemap._paintLayerLights @ MPP_MapLight.js:1019
Tilemap._paintDarknessLayer @ MPP_MapLight.js:1002
Tilemap.updateTransform @ MPP_MapLight.js:965
Tilemap.updateTransform @ TF_LayeredMap.js:386
Container.updateTransform @ pixi.js:8168
Container.updateTransform @ pixi.js:8168
Container.updateTransform @ pixi.js:8168
Renderer.render @ pixi.js:22057
Application.render @ pixi.js:23257
Graphics._onTick @ EffekseerForRPGMakerMZ_Ex.js:163
TickerListener.emit @ pixi.js:9093
Ticker.update @ pixi.js:9548
Ticker._tick @ pixi.js:9298
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9301

The "accuseth" part of MPP_MapLight.js is as follows, with the line starting with "const grad =" being line 1155 from the console output.

JavaScript:
    DarknessLayer.prototype.paintNormalMapLight = function(x, y, rgb, r, alpha) {
        const size = param_DarknessSize;
        const dx = x * size;
        const dy = y * size;
        const dr = r * size;
        const bitmap = this.bitmap;
        const context = bitmap.context;
        const grad = context.createRadialGradient(dx, dy, 0, dx, dy, dr);
        grad.addColorStop(0, `rgba(${rgb},1)`);
        grad.addColorStop(1, `rgba(${rgb},0)`);
        context.globalAlpha = alpha;
        context.globalCompositeOperation = 'lighter';
        bitmap.drawCircle(dx, dy, dr, grad);
        context.globalAlpha = 1;
    };

The wording of the error seems to suggest that there is a division with 0 happening, but I'm not seeing this... Any thoughts as to what might be the cause?
What is pMotionCrawlSpeed?
What is pMotionCrawlSpeed?
It’s a plugin parameter where you fill in at what speed you want the crawling to happen. So, in any case I got it to work by changing it to the following:

JavaScript:
var CnD_CharacterBase_realMoveSpeed = Game_CharacterBase.prototype.realMoveSpeed;
Game_CharacterBase.prototype.realMoveSpeed = function() {
    const _Tag = this.terrainTag();
    if (_Tag === pMotionCrawlTerrain && pMotionCrawlTerrain > 0){
        const mustCrawl = _Tag == pMotionCrawlTerrain && pMotionCrawlTerrain > 0 ? pMotionCrawlSpeed - 4 : 0;
        return this._moveSpeed + (this.isDashing() ? 1 : 0) + mustCrawl;
    } else {
        return this._moveSpeed + (this.isDashing() ? 1 : 0);
    }

In other words, don't call the original function, but write the contents of the original (rmmz_objects.js) function. So I suppose there is another overwrite somewhere that is the actual cause of the problem... will go on a search.

EDIT: finished searching, and there is no other overwrite in the plugins that I use...
Actually you missed a return before you call the original function.:LZSgrin:
Actually you missed a return before you call the original function.:LZSgrin:
1730712664541.gif


Oh. My. Gosh.

I'll go blush in a corner now... and maybe sob a little. Thanks!

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.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-a-conflict-when-patching-realmovespeed.173025/