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,362
Reaction score
1,644
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,362
Reaction score
1,644
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
3,356
Reaction score
2,478
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
596
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

image_2021-06-13_213812.png

Todays Lesson: Tiles are a pain to make xD
The game is not even 2% complete, but i just wanted to release something for funsies. :)
It's on my google drive.
It would be awesome if i could get a couple ideas and the like!
So yesterday Dad took me to Volcano Bay, and it was almost ruined by a thunderstorm... then it passed by and the lightning warning got lifted, leading to an awesome time sliding and swimming. Hopefully we get to go to the arcade tonight. The one we're planning on has a restaurant built in with AWESOME food. Not to mention how big the arcade itself is!
image_2021-06-13_150033.png

Maybe I'll actually try making a retro pack. Already have the shark fin made so why not xD
Hey everyone, for everybody following along with my RPG Maker MZ streams: There will unfortunately not be a stream tonight. There is a big exciting event that will go live next week that has been taking all my time, so look forward to that!

Forum statistics

Threads
112,201
Messages
1,066,540
Members
145,809
Latest member
StShiner
Top