I want to break a loop from inside my Plugin using command113(), but it doesnt work. It works however when i run it in a script using this.command113(). I logged, what "this" is and its the Game_Interpreter, but i cant use the command with Game_Interpreter.command113(). Why?
MZ Break loop in script
Javascript/Plugin Supportbecause a lot of commands are context-sensitive, and without seeing your entire code as well as getting a description of what it is supposed to do we can't tell you.
just for example - there are two different game interpreter instances, one for the map events and one for troop events.
just for example - there are two different game interpreter instances, one for the map events and one for troop events.
(And every Parallel event has its own interpreter, too.)
Well there isnt much code to show. All im doing is a loop which calls a plugin command that should end the loop. I am also calling everything from the map.
My Event looks like this:
And this is how my Plugin looks:
My Event looks like this:
And this is how my Plugin looks:
You've used an arrow function, which does not have its own
developer.mozilla.org
Also, the first input to
Assuming your plugin is named
this value:
Arrow function expressions - JavaScript | MDN
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate limitations in usage:
registerCommand should be a string. You've used a variable but haven't shown what value you've stored in that variable.Assuming your plugin is named
Test.js, try this:
JavaScript:
PluginManager.registerCommand("Test", "End", function(args) {
this.command113();
});
Bruh... thanks for the answer it works now. But i cant call the interpreter directly or can i?
You can if you actually reference it. Just saying Game_Interpreter is the name of the class, not an instance of an interpreter in the game.
$gameMap._interpreter is the interpreter for the current map.
$gameTroop._interpreter is one for troop events.
You just have to figure out how to correctly reference the interpreter that you need - and from inside an event, that's most easily
$gameMap._interpreter is the interpreter for the current map.
$gameTroop._interpreter is one for troop events.
You just have to figure out how to correctly reference the interpreter that you need - and from inside an event, that's most easily
thisHmm i tried using $gameMap._interpreter for that, but it didnt work. Might have to test that again. I tried to find it in the files, but vs code couldnt find it. Are they defined somewhere?
and where and when did you try it?
as said that is the interpreter for the current map and it will not work if you want to do something outside that map or when the map does not exist (on the title screen for example)
It comes back to your original problem: global references are restricted for security reasons, and commands other than "this" will not always be accessable anywhere.
So your first step should always be "where and in which instance and in which context does my code run?", and only after you know that you can check what is available there.
You can reference the interpreter as
this in a plugin command, because a plugin command is run in the context of the calling interpreter. Turan mentioned ways to reference the main map/troop interpreters globally, but that is not usually necessary in good code.$gameMapis an instance of theGame_Mapclass.$gameMap._interpreteris an instance of theGame_Interpreterclass on that map instance.
I think you may save a lot of time in the long run if you read up on some of the basics, such as scope, classes vs instances, and inheritance. In case you're interested, here are a couple of links (or you can find your own):
Object-oriented programming - Learn web development | MDN
This article has described the basic features of class-based object oriented programming, and briefly looked at how JavaScript constructors and prototypes compare with these concepts.
Inheritance and the prototype chain - JavaScript | MDN
In programming, inheritance refers to passing down characteristics from a parent to a child so that a new piece of code can reuse and build upon the features of an existing one. JavaScript implements inheritance by using objects. Each object has an internal link to another object called its...
Part of this comes back to the very top - why are you trying to do this via script?
You're doing in a Plugin Command, which means you're already in an event. Why on earth aren't you simply using the Break Loop event command?
You can do whatever you want in your game, but it just doesn't make sense to use code when existing event commands just work.
You're doing in a Plugin Command, which means you're already in an event. Why on earth aren't you simply using the Break Loop event command?
You can do whatever you want in your game, but it just doesn't make sense to use code when existing event commands just work.
Original thread: https://forums.rpgmakerweb.com/threads/break-loop-in-script.159628/