ReferenceError - is it me or is it the engine?

Hello,
I'm trying to create a simple teleportation script that allows the player to instantly move a certain amount of tiles into the direction they are facing.

Setup is, I have a common event that keeps listening for the button 'T' to be triggered. When that happens, it calls a plugin command which is supposed to call the teleport function.

The teleport function is
Code:
Game_Character.prototype.characterTeleport = function(){
     this.setThrough(true);
     this.setBlendMode(1);
     this.setMoveSpeed(6);
     this.setMoveFrequency(5);
     for(var i=0; i<tpRange; i++){
          this.moveStraight(tpDirection);
     }
     this.setThrough(false);
     this.setBlendMode(0);
     this.setMoveSpeed(4);
     this.setMoveFrequency(3);
}

The function for the plugin commands is
Code:
var _raen_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args){
     _raen_Game_Interpreter_pluginCommand.call(this, command, args);
     if(command === 'TeleportCharacter') characterTeleport(); //this is where the 'undefined' occurs
}

When pressing 'T' in the game, it says "ReferenceError - characterTeleport is not defined" and refers to the line I commented. I'm rather certain the syntax is correct. I assume maybe the Game_Interpreter can't call a Game_Character function? Or am I just too stupid to call a function?
why don't you just use the Transfer Player command? It has an option to not fade, and you can use variables to state the destination.
You assign the method "characterTeleport" into Game_Character prototype
And you call it in Game_Interpreter, it's on you. Unfortunately, I'm not familiar with MV code to solve the issue.
@Shaz I want an actual movement effect. It just looks cooler if the player actually zooms to the location instead of just blinking there.

@TheoAllen Yes, well, I assume that's the issue. I showed this code to a friend of mine who's a programmer and she said syntactically, the code is correct. That's why I'm asking for help here.
Ah, you said "instantly" so I assumed you mean "instantly" 🙂

@TheoAllen is correct. The plugin command is issued from the Game_Interpreter class. The teleport function is within the context of the Game_Character class. There is no such thing as characterTeleport in Game_Interpreter. You need to say, in the plugin command, $gamePlayer.characterTeleport()

However, I'm not even sure that's going to work, because within your loop to move, you're not pausing for each move to happen, and you're not doing any graphic updates.

All those commands you've got in that function can be done within a movement route. I'd try that instead, knowing that the engine is already equipped to handle the wait for each movement before starting the next, and the updating of graphics to allow the movement to be seen. If you want a "sliding" effect, you could also turn Move Animation OFF at the start and on again at the end.
@Shaz come to think of it, you're right. I can do the pure teleport/movement part without a script.
I need the script basically for 3 reasons.
1) Map the 'T' button for teleport. I couldn't get this to work in an event's script command.
2) Easy way of modifying the teleport range (I could probably do that by putting only one move into the movement route and then increase a counter).
3) Check wether the player would end up inside a wall or something, and if that's the case, reduce the teleport range to before the wall. I have to set Through to true otherwise the player couldn't teleport over/through obstacles, so turning on "skip if cannot move" won't help. But of course I don't want them to end up inside a wall or river.
How are you getting the T button to work now? You said you're doing it in a common event, and I don't see anything about it in the script, so you can just do the same thing that you're doing now.

You can modify the teleport range easily by using a variable to hold the number of steps. Do one movement route to set the through, blend mode, speed, frequency. Set a temporary variable to zero, then within a loop do a single step forward and increment the temporary variable. Do a test to see if it's equal to the variable containing the number of steps to move, and if it is, exit the loop. Then a final movement route to reset the through, blend mode, speed and frequency.

#3 is going to be the issue, but I'm not seeing how you're preventing that in the script either at the moment.

Basically, all the stuff you've got in the script, you can do with events. And some of it you're already doing with events. For #3 you might be able to use regions to define the places you can't end up once the move completes. Then before doing the move, work out where you WOULD end up, and if it's on one of these "no go" tiles, reduce the number of steps by one, and check again, until you end up on a tile that you CAN move to. This can also be done with events.
Made this just now to show how I would do teleport using events. The animations are just to give you an idea you can use anything you like to make the effect you like.
Teleport_Example.gif

Also what the event sheet looks like to get this effect.
unknown.png
As Shaz said, the problem is that while the characterTeleport function exists for Game_Character, the one being called has no Game_Character set to it to call it from. it is not even this.characterTeleport() to call it from the Game_Interpreter. so yeah, $gamePlayer.characterTeleport seems to be the better option.

But I'd definitely recommend using a plugin to map T to call a common event though.
Not only you can turn it off when you want by putting it all in a conditional branch, something harder to do with a plugin,
Even if you don't do as Shaz said, using a Transfer Player command with the destination set through variables (you can do the calculations you want on variables after all),
You can just do script calls to get the same effect as a plugin anyway. Be it for the destination calculations to check the resulting passability, or just to do it all in there, transfer included.
Ok, so after going through this again, I realized most of the things can be done via event commands. In the end, the only things that required scripting in the teleport event was to check for a region ID. And the only thing that requires a plugin is to add the "T" input to the game. Quite a lot of effort for what is in the end just a single line of code, but it works. At least this plugin is unlikely to ever become incompatible.
Now, the only problem would be to actually implement this for mobile games. But I suppose for that one would need to use a plugin like SumRndmDde's Swipe Input, and hope that they didn't change something in the engine that broke it. Sadly I don't have the means to test it.

Thanks for your help and valuable input everyone. =^,.,^=
you can check for a region id using event commands as well. Get Location Info on tab 3.
Also, while you could do Swipe Input it doesn't really fit the idea of a key in the computer, I think it would work better if you used one of the clickable images plugins around.
@Shaz Ooooh, thank you. I completely overlooked that command.

@YoraeRasante I have no idea how the controls for RPG Maker games on mobile work. Swiping just seemed logical, but in the end, it's just important that the method works. How it is mapped is up to the people using it.
touch. touch the screen at a point and the player's character with try to pathfind there, or in a selection to select it. touch with two fingers to cancel/open the menu.
thus why people use picture controls for those. better control for the player.

...aren't you "the people using it"? I mean... that seemed a pretty specific plugin attempt to be for public release...
touch. touch the screen at a point and the player's character with try to pathfind there, or in a selection to select it. touch with two fingers to cancel/open the menu.
thus why people use picture controls for those. better control for the player.

...aren't you "the people using it"? I mean... that seemed a pretty specific plugin attempt to be for public release...

I see, so basically native mobile controls work like pure mouse control. Right-click equals two-finger tap for menu and back, left-click for everything else. I wouldn't even begin to know how to get the game onto my phone without using the app store, so I couldn't test that.
Also, this isn't for my game, I just had this idea and wondered how a teleport like this could be done.
However, if I figure out a method to do something, I would like it to work in every case, even if I don't necessarily use it. If I can perfect the method for my satisfaction, maybe I'll make a tutorial out of it, and then it should always work. In this case, however, since you guys showed me I was wrong and didn't need to create a plugin to implement the teleport itself, the decision on HOW the teleport is activated is on whoever decides to use it.
I see, so it is not that someone else will be the one using it, you are just being a bit too defensive of your decision on using slide instead of a clickable image.

Well, that is on you. I just thought that, since in the computer version it is just one key, it would sense to be just one click on mobile too.
While I can see how slide would work better now that I think of it, it is harder to change the direction you are facing on mobile to teleport properly with just that... you could also just use one image per direction. Slide is useable too, but as I said less consistent.

Either way, no need to be so sensitive about it, it was just a suggestion I thought you didn't think of.
I see, so it is not that someone else will be the one using it, you are just being a bit too defensive of your decision on using slide instead of a clickable image.

Well, that is on you. I just thought that, since in the computer version it is just one key, it would sense to be just one click on mobile too.
While I can see how slide would work better now that I think of it, it is harder to change the direction you are facing on mobile to teleport properly with just that... you could also just use one image per direction. Slide is useable too, but as I said less consistent.

Either way, no need to be so sensitive about it, it was just a suggestion I thought you didn't think of.

I was merely explaining my reasoning and I didn't know there's an alternative. Both would work, and I figured in the end it's the choice of whoever uses it which method they like best. If that is considered defensive or sensitive... ah well.

Original thread: https://forums.rpgmakerweb.com/threads/referenceerror-is-it-me-or-is-it-the-engine.120635/