Help with scripting...

Hi !
I am making of a custom battle system using common events, but it has become really tedious in terms of conditional branches... I have used very basic scripting for some of the events in the system (like in the first image), but when designing enemy AI I think I have reached a wall...

I have tried to do it, for example, like this:

if ($gameVariables.value(382) == 1
{
if ($gameVariables.value(391) <= 8
{
if ($gameSwitches.value(25) == true && ($gameVariables.value(397) == 5
{ ... and so on
}
}
}

And of course it lead to syntax errors; but I have figured that even if I manage to make it that far and create nested conditional branches, I find it very difficult to edit later on (like in image 2 for example, is hard to search individual parts from the script even if I try to keep it ordered)... so I was wondering if there is a way to make a javascript file that you can activate in the script manager and later call from the script call in the events command (image 3)...

Thanks beforehand!
Hi !
I am making of a custom battle system using common events, but it has become really tedious in terms of conditional branches... I have used very basic scripting for some of the events in the system (like in the first image), but when designing enemy AI I think I have reached a wall...

I have tried to do it, for example, like this:

if ($gameVariables.value(382) == 1
{
if ($gameVariables.value(391) <= 8
{
if ($gameSwitches.value(25) == true && ($gameVariables.value(397) == 5
{ ... and so on
}
}
}

And of course it lead to syntax errors; but I have figured that even if I manage to make it that far and create nested conditional branches, I find it very difficult to edit later on (like in image 2 for example, is hard to search individual parts from the script even if I try to keep it ordered)... so I was wondering if there is a way to make a javascript file that you can activate in the script manager and later call from the script call in the events command (image 3)...

Thanks beforehand!
Do you like... Action Battle System?
I have a gane that use ABS with common event, but it's in VXAce, so I'm not sure if it can work in MV. But if you want, I can give you Demo.
This youtuber has created an custom action battle system in MV, you can ask her if you want: https://m.youtube.com/channel/UC4JhG-KMBO4yQ4BudWV-OMw
Thanks for the reply!
Not quite an ABS, it´s actually turn based... already is working fine but I am looking for a way to avoid all the nested conditional branches from the editor and call them from a script...
so I was wondering if there is a way to make a javascript file that you can activate in the script manager and later call from the script call in the events command (image 3)...
Yes. For RPG Maker MV/MZ a JS file like that is called a plugin. For example, you could save this as a .js file and import as a plugin (via the Plugin Manager):
JavaScript:
/*:
 * @plugindesc Defines some helpful functions!
 * @help Terms of use: free to use and/or modify for any project.
 */

// Global "namespace" variable (to minimise naming conflicts)
var Avanster = {};

// Define a function on that namespace
Avanster.isLessThan = function(a, b) {
  return a < b;
};
In this example, Avanster is declared as a global variable, i.e. after the plugin has been loaded, Avanster (and its properties) is accessible at any point in the game's scripts. So you should be able to do stuff like this in a Script command:

Avanster.isLessThan($gameVariables.value(1), $gameVariables.value(2));
You can define any number of functions or values on that global variable~
Thanks!
I will give it a try =)

Original thread: https://forums.rpgmakerweb.com/threads/help-with-scripting.147166/