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,422
Reaction score
1,716
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,422
Reaction score
1,716
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,127
Reaction score
4,760
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
605
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

just gonna leave this here... if ya know ya know...
:kaoswt2:
1665097246742.png
BCj
So I went to Alladin the musical, for the first time since I lost my sight. Was very stressed as I wasn't sure I could see it well. But I saw most of it sitting on row 2! Which is great. So I just booked 4 more musicals for 2023 :D
DamageEvil_7.png added!
index.php

Trying to pixel a stone and feeling like I forgot how to do pixel art in itself.

Forum statistics

Threads
125,815
Messages
1,173,823
Members
164,985
Latest member
S4ULEX
Top