[RMMV] **SOLVED** Help with scripting loop code sequence

So, I think MV uses JavaScript, which I have little idea how to write in, and I don't know how to call stuffs from rpgmaker as well ($game functions).

Basically, I want to save myself hours found this in event language as it's very cluttered, so a script should compact it:
Code:
var actor = 7; \\my actors start in seven as the six first are templates

\\Loop
for (i=actor, i<30, i++)
   array friends[];
   switch i
      case 7: friends=[8,9,14]; break;
      case 8: friends=[7,9]; break;
      case 9: friends=[7,8]; break;
      case 14: friends=[7]; break;
   \\then I want to use those as variables in a plugin call, specifically from Moogle's Actor Friendship System.
   for (j = (each element from friends[]))\\no idea how to do that
      \\main plugin command is structured as Plugin Command (a) (b) 10, where a and b are actors
      Plugin Command (i) (j) 10

      \\optional (I think I can do this eventually)
      If ((Plugin Command Getter i j)>20)
         Add state to i, id
         Add state to j, id
         (Another plugin command i, id2)

\\this will add 10 friend points between actors i and j, and because the plugin is based on One Sided Friendship, I have to do both 'friend i leader j' and 'friend j leader i'
Can someone translate that into RMMV script language? I can give the Plugin Commands and Link Page if necessary, but I think the looping function is the important but here.

If someone could at least reference some JavaScript/RMMV coding reference that would be appreciated too.

---------------

FINAL
: I got the code working with all the functions I wanted, so here's my code with comments:

JavaScript:
var actor = 7; var friend = 0;  var friendList = []; var i;
for ( leader = actor; leader < 30; leader++) {
  switch(leader) { case 7: friendList = [10, 12, 13, 14]; break; case 10: friendList = [7, 11, 13]; break; case 11: friendList = [10]; break; case 12: friendList = [7, 13]; break; case 13: friendList = [7, 10, 12]; break; case 14: friendList = [7]; break; default: }
  for (i = 0; i < friendList.length; i++) { //Setting the list of friends for each actor
    friend = friendList[i]; this.ActorDistance(2, leader, friend); console.log(friend + " " + $gameVariables.value(2)); this.ActorDistance(2, leader, friend); var Gi = new Game_Interpreter(10); //saving the distance between actors, and creating a GameInterpreter to use commands
    if ($gameVariables.value(2) <= 2 && $gameVariables.value(2) != 0) {
      Gi.pluginCommand("AFS",["Gain", 10, "Friend", friend, "Leader", leader]); //Moogle_X's Actor Friendship System plugin, adding friendship points
      Gi.pluginCommand("AFS", ["Var", 3, "Level", "Friend", friend, "Leader", leader ]); //AFS above, now saving the level between characters
      $gameActors.actor(leader).addState( $gameVariables.value(3) + 50); //Adds a state depending on friendship level, starting with lvl1 as state 51
    }
  }
}
Could you please explain what you're trying to do in detail?
This part to be exact:
\\then I want to use those as variables in a plugin call, specifically from Moogle's Actor Friendship System.
for (j = (each element from friends[]))\\no idea how to do that
\\main plugin command is structured as Plugin Command (a) (b) 10, where a and b are actors
Plugin Command (i) (j) 10
This is as far as I could understand lol
Spoiler
JavaScript:
var actor = 7;
friends = []
for (i = actor; i < 30; i++) {
    if (i == 7) {
        friends = [8, 9, 14]
    } else if (i == 8) {
        friends = [7, 9]
    } else if (i == 9) {
        friends = [7, 8]
    } else if (i == 14) {
        friends = [7]
    }
    for (j = 0; j < friends.length; i++) {
        //Idk what you're trying to do here lol
    }
}
Sure! I want to go between each value in the friends[] array, so if Actor is 7, j would be 8, then 9, then 4, then it would change the actor (i).
This is as far as I could understand lol
JavaScript:
var actor = 7;
friends = []
for (i = actor; i < 30; i++) {
    if (i == 7) {
        friends = [8, 9, 14]
    } else if (i == 8) {
        friends = [7, 9]
    } else if (i == 9) {
        friends = [7, 8]
    } else if (i == 14) {
        friends = [7]
    }
    for (j = 0; j < friends.length; i++) {
        //Idk what you're trying to do here lol
    }
}
I have no problem in doing if elses if there's no switch, thanks!

As for the plugin command, it's from Moogle_X's Actors Friendship System
Link: https://forums.rpgmakerweb.com/index.php?threads/moogle_xs-actors-friendship-system.123632/
The command is 'AFS Gain x Friend y Leader z', where I want x=10, y=j, z=i

EDIT: in [for (j = 0; j < friends.length; i++)], shoudn't that be a j++? Otherwise it would freeze... Yeah, I know i and j are easy to get mixed, but I'm used to them from my minimal code classes. You can change to x and y or whatever if you want.
Yeah that's a typo. I'm too used to using i for loops.
That part will be
for (j=friends; j<friends.length; j++){//stuff}
OK, I think I found my way in. I'll be checking each unit off the array with:
JavaScript:
var index;
var a = ["a", "b", "c"];
for (index = 0; index < a.length; ++index) {
    console.log(a[index]);
}
I'll need to use Yanfly's Script Call Plugin Commands too.
The final code looks like this (although horizontal due to 12-line limit in RMMV):
JavaScript:
var actor = 7; var friend;  friendList = []; var index;
for ( leader = actor; leader < 30; leader++) {
  switch(leader) { case 7: friendList = [8, 9, 14]; break; case 8: friendList = [7,9]; break; case 9: friendList = [7,8]; break; case 14: friendList = [7]; break; } \\this will grow as more actors are added to the game
  for (index = 0; index < friendList.length; ++index) {
    friend = friendList.[index]; this.ActorDistance(2, leader, friend); \\Command from SRPG plugin
    if ($gameVariables.value[2] <= 2) {
      AFS Gain 10 Friend friend Leader leader;
      console.log(friendList[index] + " and " leader);
    }
  }
}
I'll be testing it right now.

EDIT: I discovered that commands need some special syntax. I also added the rest of the logic, adding states to characters.
Code as of now:

JavaScript:
var actor = 7; var friend;  friendList = []; var index;
for ( leader = actor; leader < 30; leader++) {
  switch(leader) { case 7: friendList = [8, 9, 14]; break; case 8: friendList = [7,9]; break; case 9: friendList = [7,8]; break; case 14: friendList = [7]; break; } \\this will grow as more actors are added to the game
  for (index = 0; index < friendList.length; ++index) {
    friend = friendList.[index]; this.ActorDistance(2, leader, friend); \\Script command from SRPG plugin, this one works on scripts fine.
    if ($gameVariables.value[2] <= 2) {
      $gameMap._interpreter.pluginCommand("AFS", [ "Gain", "10", "Friend", friend, "Leader", leader ]); \\Command is AFS Gain x Friend y Leader z. Increases points between friend and leader.
      $gameMap._interpreter.pluginCommand("AFS", [ "Var", "3", "Level", "Friend", friend, "Leader", leader ]); \\Command is AFS Var x Level Friend y Leader z. Sets variable 3 to the friendship level.
      $gameActors.actor(leader).addState( $gameVariables.value[3] + 50); \\ Adds support states, which begin at 51 for level 1.
    }
  }
}
This will be called every turn switch between actors and enemies in a slow tbs game, so LAG shoudn't be that much of a bother.
Oh man, a lot of mistakes were tweaked in my multiple edits, but it's not working still
Current script:
JavaScript:
var actor = 7; var friend = 0;  var friendList = []; var index;
for ( leader = actor; leader < 30; leader++) {
  switch(leader) { case 7: friendList = [10, 12, 13, 14]; break; case 10: friendList = [7, 11, 13]; break; case 11: friendList = [10]; break; case 12: friendList = [7, 13]; break; case 13: friendList = [7, 10, 12]; break; case 14: friendList = [7]; break; default: } \\\this will grow as more actors are added to the game
  for (index = 0; index < friendList.length; index++) {
    friend = friendList[index]; this.ActorDistance(2, leader, friend); \\\Script command from SRPG plugin, this one works on scripts fine.
    if ($gameVariables.value[2] <= 2) {
      $gameMap._interpreter.pluginCommand("AFS", [ "Gain", "10", "Friend", friend, "Leader", leader ]); \\\Command is AFS Gain x Friend y Leader z. Increases points between friend and leader.
      $gameMap._interpreter.pluginCommand("AFS", [ "Var", "3", "Level", "Friend", friend, "Leader", leader ]); \\\Command is AFS Var x Level Friend y Leader z. Sets variable 3 to the friendship level.
      $gameActors.actor(leader).addState( $gameVariables.value[3] + 50); \\\ Adds support states, which begin at 51 for level 1.
    }
  }
}

EDIT: Strangely, Console is telling me that script gets an error from YEP_SkillCore... Game is working as intended, aside the script function.
Spoiler: print
1602725572056.png

EDIT2: I started testing it one line at a time, and after some time at forums and correcting syntax, I got it working!!

JavaScript:
var actor = 7; var friend = 0;  var friendList = []; var i;
for ( leader = actor; leader < 30; leader++) {
  switch(leader) { case 7: friendList = [10, 12, 13, 14]; break; case 10: friendList = [7, 11, 13]; break; case 11: friendList = [10]; break; case 12: friendList = [7, 13]; break; case 13: friendList = [7, 10, 12]; break; case 14: friendList = [7]; break; default: }
  for (i = 0; i < friendList.length; i++) {
    friend = friendList[i]; this.ActorDistance(2, leader, friend); console.log(friend + " " + $gameVariables.value(2)); this.ActorDistance(2, leader, friend); var Gi = new Game_Interpreter(10);
    if ($gameVariables.value(2) <= 2 && $gameVariables.value(2) != 0) {
      Gi.pluginCommand("AFS",["Gain", 10, "Friend", friend, "Leader", leader]);
      Gi.pluginCommand("AFS", ["Var", 3, "Level", "Friend", friend, "Leader", leader ]);
      $gameActors.actor(leader).addState( $gameVariables.value(3) + 50);
    }
  }
}

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/rmmv-solved-help-with-scripting-loop-code-sequence.128507/