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,429
Reaction score
1,722
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,429
Reaction score
1,722
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,393
Reaction score
5,085
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

Can Elon crash Twitter faster? I want something as big to replace it so I can promote my game there. I also need to actually do promotion this time, heh.
Thinking of getting a mechanical keyboard, eventually! Would anyone be interested in a chill keycap-painting stream?
Walked through the rain to take pictures of an 50+ year old printing press for my students. Hope they will honor that effort xD
Can I promote my %75 OFF Creator Day Sale here, or it's against forum rules as well? :kaocry:
Tests for an alert system that spawns enemy reinforcements, as a stealth game should do :kaoswt2:

Forum statistics

Threads
126,910
Messages
1,182,255
Members
166,713
Latest member
escuro
Top