function.call doesn't work in my plugin

dayseven0314

Villager
Member
Joined
Jul 25, 2017
Messages
6
Reaction score
1
First Language
Chinese
Primarily Uses
RMMV
rpg_objects:
===========================================================================
Game_CharacterBase.prototype.isMapPassable = function(x, y, d) {
var x2 = $gameMap.roundXWithDirection(x, d);
var y2 = $gameMap.roundYWithDirection(y, d);
var d2 = this.reverseDir(d);
return $gameMap.isPassable(x, y, d) && $gameMap.isPassable(x2, y2, d2);
};
===========================================================================



my plugin :
===========================================================================
var _Game_CharacterBase_prototype_isMapPassable = Game_CharacterBase.prototype.isMapPassable;
Game_CharacterBase.prototype.isMapPassable = function(x, y, d){
_Game_CharacterBase_prototype_isMapPassable.call(this, x, y, d);
};
===========================================================================
it doesn't work!
player character can't move.




but if I change to this in my plugin :
===========================================================================
Game_CharacterBase.prototype.isMapPassable = function(x,y,d){
var x2 = $ gameMap.roundXWithDirection(x,d);
var y2 = $ gameMap.roundYWithDirection(y,d);
var d2 = this.reverseDir(d);
return $gameMap.isPassable(x,y,d)&& $gameMap.isPassable(x2,y2,d2);
};
===========================================================================
now it work...
player character is movable.
 

Eliaquim

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,339
Reaction score
591
First Language
Portuguese - Br
Primarily Uses
RMMV
Hi!
This happens because the original function is returning a value.
And in your first attempt, you are not returning anything.

You have to do this:

JavaScript:
var _Game_CharacterBase_prototype_isMapPassable = Game_CharacterBase.prototype.isMapPassable;
Game_CharacterBase.prototype.isMapPassable = function(x, y, d){
const alias = _Game_CharacterBase_prototype_isMapPassable.call(this, x, y, d); // Here you are saving the original value
    // do your thing;
    return alias; // And here you are returning it :)
};
 

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

Latest Threads

Latest Posts

Latest Profile Posts


:3c here's a thing i made a while while while back
Tried mochi for the first time. It's quite nice. Has a pleasant smell and taste, and is nice and chewy.
made a bio for the protag in my project!
Beggar : "I haven't eat for days..."
Kid : "Just do crime! You will get daily necessity for free in prison~"

Forum statistics

Threads
99,159
Messages
962,454
Members
130,725
Latest member
teendinsaikha
Top