Jump to content

Simple Question: For $n


Recommended Posts

For $n = 1 to 10
MouseClick("left",422,183); Open
sleep(15000); Pause for 15 seconds

For $n = 1 to 2


MouseClickDrag($MOUSE_CLICK_LEFT, 362, 384, 436, 384)
sleep(1000); Pause for 1 seconds

MouseClick("left",1585,205); 1
sleep(1000); Pause for 1 seconds
MouseClick("left",1341,205); Click 
sleep(1000); Pause for 1 seconds
MouseClick("left",1341,205); Click 
sleep(10000); Pause for 10 seconds


   Next

MouseClick("left",1442,941); Close
sleep(2000); Pause for 2 seconds

Next

I need the above code to test a program i want to create but so far its not working.  I want it to Open the program, then do a series of clicks two times as indicated by middle For loop, then i need it to close the program and rest for 2 seconds. Then start all over again and do this for a total of 10 times as indicated by the main For loop. 

 

So far what happens is that everything runs 1 time, and doesn't do the remaining 9 times. Can anyone help me fix it?

Link to comment
Share on other sites

@boat_58

Use a different counter.

Instead of $n, use $m, or the classic $i and $j.

Add some ConsoleWrite() in each For so you can see what's going on.

By the way, Mouse* functions are not the best solution to automate things.

If you tell us what you are trying to automate, there could be a better solution that fits your needs :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Francesco is correct. Look at the output from this modified script:

For $n = 1 to 10
MouseClick("left",422,183); Open
sleep(5000); Pause for 15 seconds

    For $n = 1 to 2
        MouseClickDrag($MOUSE_CLICK_LEFT, 362, 384, 436, 384)
        sleep(1000); Pause for 1 seconds

        MouseClick("left",1585,205); 1
        sleep(1000); Pause for 1 seconds
        MouseClick("left",1341,205); Click
        sleep(1000); Pause for 1 seconds
        MouseClick("left",1341,205); Click
        sleep(1000); Pause for 10 seconds
        ConsoleWrite("End loop 2: $n = " & $n & @CRLF)
   Next

MouseClick("left",1442,941); Close
sleep(2000); Pause for 2 seconds
ConsoleWrite("End loop 1: $n = " & $n & @CRLF)
Next

image.png.f0efc0482d8c44148a1af7f95798ad40.png

It's creating an infinite loop because every time it enters the second loop, it resets $m to 1. Use two separate variables for nested loops to avoid this.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...