MV (Solved) My first plug-in (for RPGMV)

Hello all
In my game I've gone and made this script:
Code:
if(this.getSelfSwitchValue(1, 13, 61) === true)
{
   var value = this.getSelfVariableValue(1, 13, 21);
   this.setSelfVariableValue(1, 13, 21, value - 1)
   if (this.getSelfVariableValue(1, 13, 21) <= 0)
   {
       this.setSelfSwitchValue(1, 13, 61, false)
       Yanfly.MorphEvent(13, 4, 5, true);
   }
   else {$gameSelfSwitches.setValue([ 1, 13, "B"], true)}
}

The thing is I've reached the max lines the script window can use and I want to add to it and I don't want to make it into a one liner.
So a solution I saw to this problem was to make a plugin of my own and insert the code there,
problem is.
1. Its using two different Yanfly plugins.
Event Morpher
Self Switches & Variables
2. I don't have any coding knowledge

I am using the template for a plugin from this post - The anatomy of a plugin by Trihan.
so my question is:
Can I simply copy my script call into my makeshift plugin, put the plugin at the bottom of my plugin list and hope it works
or do I need to reference the functions that are comming from this two plugins into my own?

thank you for taking the time to read this.
Can I simply copy my script call into my makeshift plugin, put the plugin at the bottom of my plugin list and hope it works
Unless you wrap it in a function and call the function from the game this will be read only once and you have no control over when it's executed.
do I need to reference the functions that are comming from this two plugins into my own?
You're already referencing them. If those plugins are installed in your project the engine can call functions in them from your plugin.

That said, you don't need all the white space after the curly braces and such, so if the only reason you're doing this is because it won't fit in the script window, you can delete the white space. The white space is good coding practice for human readability but is not necessary for the computer to read the code.
Not quite a copy / paste unfortunately.

Your script sits inside an event, right? So when the event code runs, your script gets executed.

If you move your script into a plugin, you still need a way to tell the game engine, when the event code runs, I want my plugin code to get executed.

Code:
var my_Game_Interpreter_pluginCommand =
    Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
    my_Game_Interpreter_pluginCommand.call(this, command, args)
    if (command === 'RunMyCode') this.RunMyCodeFunction();
};

Game_Interpreter.prototype.RunMyCodeFunction = function () {
code you want to execute
};

Then in the event, you can now use a plugin command: RunMyCode
and your code will be executed.

Now you have a lot of this references to the game map event in your script. I don't remember whether or not the keyword this will work when you call the plugin command like that.
@AquaEcho @TESTOSTERONE
thank you both for your advises I shall try them and hopefully update
this post that it has worked.
The thing is I've reached the max lines the script window can use and I want to add to it and I don't want to make it into a one liner.
Unfortunately, what you want and what you have the coding knowledge to easily do are two different things.

Why don't you just make it some more compact? There is a difference between "too big to fit in a script box" and "one line."

You can free up four whole lines just by moving the braces so they're not on their own lines, like you did with the "else" at the end.

(incidentally, those braces are meaningless. You only need to use them when you're creating a code block with more than one statement, things like if/else automatically apply to the next single statement)

Now you have a lot of this references to the game map event in your script. I don't remember whether or not the keyword this will work when you call the plugin command like that.
Because you made it a method of Game_Interpreter, it should.
another way (if you save it), you can make a 1 liner to stay below it 11 lines max.

or a simple function:

farmer = function() {
// your code
}

than call farmer() to execute the code.

there are some methodes and it depends if you need it multiple times or not.
depends on your mechanic and approaches.
You could also save space by making it more efficient.

What's the point in taking up a line to declare a variable that you use just once?
Code:
   var value = this.getSelfVariableValue(1, 13, 21);
   this.setSelfVariableValue(1, 13, 21, value - 1)
Code:
this.setSelfVariableValue(1, 13, 21, this.getSelfVariableValue(1, 13, 21)-1);

You're also inconsistent in your use of semicolons - they're not syntactically required for JavaScript, but they are better practice to include at the end of statements.
You've got plenty of other help here, so I'm just popping in to say thank you for using my tutorial thread! <3
@TESTOSTERONE @ATT_Turan
Thank you both for your contribution
I was able to achieve what I wanted and also learn a few things on the way.

Original thread: https://forums.rpgmakerweb.com/threads/solved-my-first-plug-in-for-rpgmv.161472/