Lain

return "hi";
Member
Joined
Mar 11, 2017
Messages
10
Reaction score
1
First Language
German
Primarily Uses
RMMV
Hi again,

I want to Alias "Game_CharacterBase.prototype.canPass", but doing so prevents the player from moving at all.

Original code:
PHP:
Game_CharacterBase.prototype.canPass = function(x, y, d) {
    var x2 = $gameMap.roundXWithDirection(x, d);
    var y2 = $gameMap.roundYWithDirection(y, d);
    if (!$gameMap.isValid(x2, y2)) {
        return false;
    }
    if (this.isThrough() || this.isDebugThrough()) {
        return true;
    }
    if (!this.isMapPassable(x, y, d)) {
        return false;
    }
    if (this.isCollidedWithCharacters(x2, y2)) {
        return false;
    }
    return true;
};

Aliased version that doesn't work:
PHP:
var alias_Game_CharacterBase_canPass = Game_CharacterBase.prototype.canPass;
Game_CharacterBase.prototype.canPass = function(x, y, d) {
    alias_Game_CharacterBase_canPass.call(this,x,y,d);
};

It seems to automatically return false, so the player can't move at all. The player can still turn around and everything but moving works.

I want to avoid overwriting. Any ideas?
 

Galv

Veteran
Veteran
Joined
Oct 1, 2012
Messages
1,431
Reaction score
1,723
First Language
English
Primarily Uses
RMMZ
You will see in the original function that it uses 'return' to return something when the function is run.
In your alias, you aren't returning anything.

Try putting return before your alias call
 

Lain

return "hi";
Member
Joined
Mar 11, 2017
Messages
10
Reaction score
1
First Language
German
Primarily Uses
RMMV
That works, thank you! But now I am a bit concerned about functions that return things only under certain conditions.
 

Galv

Veteran
Veteran
Joined
Oct 1, 2012
Messages
1,431
Reaction score
1,723
First Language
English
Primarily Uses
RMMZ
I am not sure what your concern is about that.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
5,441
Reaction score
5,126
First Language
English
Primarily Uses
RMMZ
That's how return values work, Lain. In your alias you're calling a function that returns a value, but then you're not doing anything with it. A program will only do something with a return value if you tell it to.
 

mogwai

1984
Veteran
Joined
Jun 10, 2014
Messages
875
Reaction score
606
First Language
English
Primarily Uses
RMMV
If you return the alias function, it will handle all the conditions.
 

Lain

return "hi";
Member
Joined
Mar 11, 2017
Messages
10
Reaction score
1
First Language
German
Primarily Uses
RMMV
Ah I see, thanks. I was not sure, if I had to use return or not on functions that only return stuff under conditions.
 

Latest Threads

Latest Profile Posts

Looks like the Twitter purge may be happening very soon. I tweeted on an old account for the first time in years. I'm also keeping an eye out on a specific username that I've been eyeing for years.
Quick sketch from yesterday, how's everyone doing? :kaohi:
LMzVpQY.jpg

Character: Filia from Skullgirls
Another screenshot of a completed area on the Great Plateau. You can see the tree branch equipped in the slots on the bottom middle of the screen. You can also see Hylian Shrooms that can be picked (Link is facing them). Also, apples are in the tree.

screenshot2.png
Went to lasertag for the first time, came out 5th out of 12. Take that sports teacher who said I'd be going nowhere physicalwise xD
What if your boss were like this guy?

kuestsdynamisxp001.jpg

Forum statistics

Threads
127,127
Messages
1,184,205
Members
167,079
Latest member
DAVI_RN
Top