Do we need to use 'this' in the Script Command?

I have a function set up like this:

Game_Interpreter.prototype.myFunction = function(args) { // do stuff here};Then I add a Script Command:
Code:
myFunction(1, 2, 3)
When I run it, I get

Reference Error.

myFunction is not defined

Do I need to call it like this:

Code:
this.myFunction(1, 2, 3)
to get it to run a function in Game_Interpreter?
Yes.

Everything that is not global needs the "this".

One solution would be to create global methods that call the local methods from the game interpreter:

Code:
function myFunction(){  return $game_map.interpreter.myFunction();}
But that is... not really nice.
no 🙁 I was hoping there'd be a way to just call myFunction without needing this and without declaring it as a global function.


I may just not include the ability to do script calls in that case.


Thanks.
You can update the game interpreter to evaluate locally

Game_Interpreter.prototype.command355 = function() { var script = this.currentCommand().parameters[0] + '\n'; while (this.nextEventCode() === 655) { this._index++; script += this.currentCommand().parameters[0] + '\n'; } eval(this, script); return true;};Then you don't need to use `this`However, this requires everyone to do it.
yeah, I'm not into making other people change their scripts.


I'll just leave it out. Was going to try making a plugin that would run either through plugin commands or script commands.
You can update the game interpreter to evaluate locally


Then you don't need to use `this`


However, this requires everyone to do it.
I don't think this would work for what Shaz wants to do, but I'm too tired and may be seeing things wrong.
Nope, using this to evaluate as the context won't work,

you have to wrap it inside an anonymous function:

(function () {function myFunction() {}Game_Interpreter.prototype.command355 = function() {var script = this.currentCommand().parameters[0] + '\n';while (this.nextEventCode() === 655) {this._index++;script += this.currentCommand().parameters[0] + '\n';}eval(script);return true;}})();But it won't work if two people do that...
Thanks for the post, Shaz. I actually have a problem and was wondering why I was doing lots of commands in the interpreter and it doesn't work. It says all my functions are not declared, yet they were in Game_Interpreter.
when referencing any function any where, tinside the same class, you need the concept of this.functionNameYouWant. If you are using functions like forEach or .map then you do:

Code:
var self = thissomething.map(function(something){  self.someFunctionNameYouWant(something);})

Original thread: https://forums.rpgmakerweb.com/threads/do-we-need-to-use-this-in-the-script-command.50243/