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
592
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 Profile Posts

Is it strange that dropping acid is improving my game development?
I'm starting to wonder if I should go the Half Minute Hero route with my game. The character's main weapon is logistically way too strong. So I can't really let the player continuously grow it.... But if they had to build it up each time like HMH, that could work. Also it lets me take advantage of my randomly generated maps so much more. Hmm... This could work! :LZSexcite:
std::vector, std::map and std::string. Three reasons why I'd take C++ over C. :D

Forum statistics

Threads
99,202
Messages
962,981
Members
130,787
Latest member
Ticomanel
Top