1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[need help]Javascript and Imacros arrays question

Discussion in 'General Scripting Chat' started by walandio, Jul 2, 2013.

  1. walandio

    walandio Senior Member

    Joined:
    Jun 27, 2008
    Messages:
    1,198
    Likes Received:
    684
    Location:
    Pilipinas
    Hey there,

    I am not really a coder, but I want to create an imacros using javascript. I would like to know how to loop an array in imacros.
    What I want is to loop an Imacro function and choose different array everytime it loops.

    Here is the code that I would like to create. This code works without error. But it doesn't work the way i want it. This code only choose the last array and doesn't even loop.

    Code:
    var warray = ['apple', 'banana', 'orange'];
    
    var text = 'walandio';
    
    for(var i = 0; i < warray.length; i++)
    {
    walandio = "CODE:";
    walandio += "VERSION BUILD=8300326 RECORDER=FX" + "\n";
    walandio += "TAB T=1" + "\n";
    walandio += "TAG POS=1 TYPE=BUTTON ATTR=TXT:enter" + "\n";
    walandio += "WAIT SECONDS=3" + "\n";
    walandio += "TAG POS=1 TYPE=LI ATTR=TXT:" + warray[i] + "\n";
    walandio += "WAIT SECONDS=3" + "\n";
    walandio += "TAG POS=R1 TYPE=BUTTON ATTR=TXT:enter" + "\n";
    walandio += "WAIT SECONDS=5" + "\n";
    	
    }
    iimPlay(walandio);
    
    I hope someone can help me make this thing work..

    thanks,
     
  2. Repulsor

    Repulsor Power Member

    Joined:
    Jun 11, 2013
    Messages:
    712
    Likes Received:
    267
    Location:
    PHP Scripting ;)
    Add the last line inside the for loop :)
    Code:
    
    iimPlay(walandio);
     
    • Thanks Thanks x 1
  3. walandio

    walandio Senior Member

    Joined:
    Jun 27, 2008
    Messages:
    1,198
    Likes Received:
    684
    Location:
    Pilipinas
    wew.. thanks so much man..

    it works..
     
  4. Repulsor

    Repulsor Power Member

    Joined:
    Jun 11, 2013
    Messages:
    712
    Likes Received:
    267
    Location:
    PHP Scripting ;)
    I know ;) Because the error was a logical error.

    What you were doing in the codes was, inside the loop, first you set the variable with details with the first array item, then change it again with the second, then the third again, and then as the loop finishes, it is being played.

    To play all of them, you want to play as they the variables are set with details. i.e inside the loop. So it is played 3 times. Not just one time with the last array item.
     
    • Thanks Thanks x 1
  5. walandio

    walandio Senior Member

    Joined:
    Jun 27, 2008
    Messages:
    1,198
    Likes Received:
    684
    Location:
    Pilipinas
    very well explained man your such an awesome coder..