0
var clientBASE = new User();
var username = ["Username1","Username2"];
var password1 = ["Password1","Password2"];
var arrayLength = username.length;
var i;

for(i=0; i < arrayLength; i++){
    client.logOn({
        "accountName": username[i],
        "password": password1[i],
    });
{

clientBASE.on('loggedOn', function(details) {
    console.log("Logged into Server as " + clientBASE.userID.getUserID());
    clientBASE.setText("Logged in");
    console.log("Logged In");
    clientBASE.logOff();

});

}

At the moment the script just currently logs into Username2 and skips username1 The script should log into username1, run the code, pause, then log into username2 and run the same code.

Any help would be appreciated

  • 3
    Java != Javascript – Pradeep Simha Feb 05 '19 at 20:12
  • 1
    logs in a user, sends a message they are logged in, then logs them out, however at the moment it only logs into username2, or the last of the array, it doesnt log into the individual accounts – Mike Junior Feb 05 '19 at 20:14
  • 1
    Java and JavaScript are two different things. When posting questions about JavaScript, do *NOT* put the `java` tag. clientBASE.setText("Logged in"); Extra quotation mark. –  Feb 05 '19 at 20:14
  • Can you please try running without event listener ClientBASE.on line, performing actions directly in a synchronous way.. Then use try catch if login fails.. – estinamir Feb 05 '19 at 20:20
  • 1
    where is the code for `clientBase` and `User` – Thomas Valadez Feb 05 '19 at 20:21
  • the code runs it just always takes the last in the array as username and password, i thought this was more to do with a logic error than anything, i tried without logOff(), and still same result – Mike Junior Feb 05 '19 at 20:26
  • so instead of going through both both elements in the array it only uses the last one and prints it twice – Mike Junior Feb 05 '19 at 20:30
  • 1
    @MikeJunior we don't know what `logOff()`, `logOn()`, `ClientBase`, or `User` are supposed to do nor what their code looks like. Edit your question to include the code for those and also include the purpose of the script. These are all things that are required for a post on StackOverflow. No worries though, I did the same thing my first time. – Howard P Feb 05 '19 at 20:31
  • 1
    See https://stackoverflow.com/questions/13343340/calling-an-asynchronous-function-within-a-for-loop-in-javascript – guest271314 Feb 05 '19 at 20:40

0 Answers0