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,446
Reaction score
1,734
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,446
Reaction score
1,734
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,999
Reaction score
5,955
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 Posts

Latest Profile Posts

Upgraded my avatar to be cuter.
When you look for several things for ages and then suddenly find it all at once.

Status.png
Status2.png
equip.png
I'm going to see if I can set up a triple booting setup. Windows for standard use & gaming, debian for linux development and manjaro for linux gaming, wine & proton use.
Who's got 2 thumbs and discovered an issue with his plugin after deleting the last fully functional copy? This guy xD
Well after a bit of a health break, back to streaming. Going to start in about 30 minutes.


...Also bored and figured I'd stream early on an off day. :LZSsmile:

Forum statistics

Threads
129,698
Messages
1,204,387
Members
170,762
Latest member
zaprobaa
Top