Script Event Command in RPG Maker MV

Hello Everyone,

I am a bit new so sorry if my question is very basic.

I am trying to write some longer script in RPG Maker MV. Unfortunately, the event command only gives you room for about 12 lines for the script and I have multiple conditional branches and I want to include comments so that I can follow the code. Is there a way that I can get more lines for scripting in the event commands? Would I need a plugin for this?

Also, I have tried continuing my conditional statement by adding another script event command where I left off but I end up getting an error.

Any advice is appreciated.
JavaScript only parses newlines as a safety measure: typically a "line" of JS ends with a semi-colon. So, for example, these two snippets are equivalent:
Code:
var vId = 5, sId = 1;
if ($gameVariables.value(vId) >= 10) {
  $gameSwitches.setValue(sId, true);
};
Code:
var vId = 5, sId = 1; if ($gameVariables.value(vId) >= 10) { $gameSwitches.setValue(sId, true); };
Since (I think?) line length is limited, this means your script calls can actually be as long as you like. 😤

I suggest writing it out in a readable way (indents etc) in Notepad or something first, then use that as a reference for entering it into the editor's script box. 😮‍💨

Script calls are passed through an eval (slow, inefficient), so if your script is particularly long then you may want to consider writing it up in a separate script file (i.e. a plugin) and simply call that code from your script call. If you want more details on that approach then someone here can probably help with that. 🙂
JavaScript only parses newlines as a safety measure: typically a "line" of JS ends with a semi-colon. So, for example, these two snippets are equivalent:
Code:
var vId = 5, sId = 1;
if ($gameVariables.value(vId) >= 10) {
  $gameSwitches.setValue(sId, true);
};
Code:
var vId = 5, sId = 1; if ($gameVariables.value(vId) >= 10) { $gameSwitches.setValue(sId, true); };
Since (I think?) line length is limited, this means your script calls can actually be as long as you like. 😤

I suggest writing it out in a readable way (indents etc) in Notepad or something first, then use that as a reference for entering it into the editor's script box. 😮‍💨

Script calls are passed through an eval (slow, inefficient), so if your script is particularly long then you may want to consider writing it up in a separate script file (i.e. a plugin) and simply call that code from your script call. If you want more details on that approach then someone here can probably help with that. 🙂

along with what caethyril said, i also like to make scripts inside moveroutes and conditional branches as convenient for me as i can.

for instance a simple range check of this inside a conditional branch script:
Code:
Math.abs($gameMap.event(e).x - $gamePlayer.x) <= 2 && Math.abs($gameMap.event(e).y - $gamePlayer.y) <= 2

i change so if i need to edit it real quick(remember the script window is so small for a conditional branch command) i use this to make it easier to change:
Code:
var d = 2; Math.abs($gameMap.event(e).x - $gamePlayer.x) <= d && Math.abs($gameMap.event(e).y - $gamePlayer.y) <= d;

now i just gotta change the d variable at begin to whatever i need, which is easily visible inside the conditional branch script window.

its the small things!! 😀
and depending on what exactly you want, you can write the functions inside a plugin that simply makes them available for global access without any other change in the engine, and then simply use the function call in the script box to run that entire longer code.
After all that is what script calls are and what the script box is intended for: to call the larger script functions from the engine whereever needed.
Thank you everyone for the quick responses. I have tried out caethyril and Bazrat's recommendations and for now that it working for my events. I am going to start watching some tutorials on plugins because I imagine that will be helpful in the long term as my scripts get more complex.

Original thread: https://forums.rpgmakerweb.com/threads/script-event-command-in-rpg-maker-mv.109825/