Sign in to follow this  
Followers 0
SilvaDreams

Mildly confused newbie

13 posts in this topic

Alright my I just started attempting to code with AutoIt about two days ago and started with some fairly basic repeating scripts, I've since moved on to something a bit harder which moves and loops through doing the same task a few times before moving to another area and doing something else.

Unfortunately I seem to have stumbled over my own feet while trying to use variables, while I can get it to add to the count so it keeps track of how many times it has done that task before moving on to the next at the end of the script I can't get it to reset those variables back to 0 (the starting value)

$ExitKey="{ESC}"
$a=0
$b=0
$c=0
HotKeySet($Exitkey, '_Exit');
Sleep(5000);
While 1 < 2   
    Do
MouseClick("left",317,159,3,0); 
    Sleep(1000);
MouseClick("left",592,379,1,0);
    Sleep(500);
MouseClick("left",598, 465,1,0); 
        Sleep(500);
MouseClick("left", 459,297,1,0); 
        Sleep(500);
MouseClick("left", 377,471,1,0); 
Sleep(6000);
    MouseClick("left",560,357,1,0); 
    Sleep(500);
$a=$a+1
Until $a=10
If $a=10 Then
    Do
MouseClick("left",163,616,1,0); 
     send("/auto{ENTER}");
     sleep(500);
MouseClick("left",372,321,1,0); 
     sleep(500)
MouseClick("left",565,539,1,0);
     Sleep(26000);
MouseClick("left",135,624,1,0); 
     sleep(500);
Send("/auto{ENTER}"); 
     sleep(500);
MouseClick("left",361,306,1,0);
     sleep(500);
MouseClick("left",565,539,1,0);
     Sleep(13000);
MouseClick("left",291,122,3,0); 
     Sleep(1000);
MouseClick("left",499,107,1,0); 
     Sleep(500);
$b=$b+1
Until $b=1
If $b=1 Then
    Do
MouseClick("left",514,489,1,0); 
    Sleep(500);
MouseClick("left",542,365,1,0); 
    Sleep(500);
$c=$c+1
    Until $c=10
If $c=10 Then
Do   
MouseClick("left",163,488,1,0);
    Sleep(500);
MouseClick("left",131,622,1,0);
    Sleep(500);
Send("/auto{ENTER}"); 
    Sleep(500);
MouseClick("left",370,354,1,0);
    sleep(500);
Mouseclick("left",565,536,1,0);
    sleep(8000);
MouseClick("left",131,622,1,0);
    Sleep(500);
Send("/auto{ENTER}"); 
    sleep(500);
MouseClick("left",372,386,1,0);
    Sleep(500);
MouseClick("left",564,539,1,0);
    Sleep(9500);
MouseClick("left",131,622,1,0);
    Sleep(500);
    Send("/auto{ENTER}"); 
MouseClick("left",376,402,1,0);
    Sleep(500);
MouseClick("left",564,539,1,0);
    sleep(12500);
MouseClick("left",131,622,1,0);
    Sleep(500);
    Send("/auto{ENTER}"); 
MouseClick("left",373,418,1,0);
    Sleep(500);
MouseClick("left",564,539,1,0);
    sleep(20600);
    MouseClick("left",131,622,1,0);
    Sleep(500);
    Send("/auto{ENTER}"); 
MouseClick("left",376,290,1,0);
    Sleep(500);
MouseClick("left",564,539,1,0);
    sleep(8500);
$c=$c+1
Until $c=1
If $a=10 Then $a=$a-10 
If $b=10 Then $b=$b-10
If $c=1 Then $c=$c-1
EndIf
EndIf
EndIf
WEnd
Func _Exit()
        Exit
EndFunc

Share this post


Link to post
Share on other sites



How's this work for you?

If $a>=10 Then $a=0
If $b>=10 Then $b=0
If $c>=1 Then $c=0

I used ">=" just in case your variables have an extra number added to it. I didn't run your script so I can't say for sure what the variables equal when it gets to that point.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

How's this work for you?

If $a>=10 Then $a=0
If $b>=10 Then $b=0
If $c>=1 Then $c=0

I used ">=" just in case your variables have an extra number added to it. I didn't run your script so I can't say for sure what the variables equal when it gets to that point.

Nope that didn't seem to work oddly enough,, still still loops back as if the initial A variable is still set to 10 and starts half way through the script

Share this post


Link to post
Share on other sites

I've tried multiple ways, and I can't seem to get it to not loop back and skip the first part of the code. Not sure if I goofed somewhere else in my code but it doesn't seem like it as anyhting else I try murder the code

If $a>0 Then $a=0
If $a=10 Then $a=0

Share this post


Link to post
Share on other sites

Try this. I've slightly modified your script, mostly just added indents, but I did add/change code a bit too. If this does what you want, compare it to your script to see the changes I've made.

$ExitKey="{ESC}"
$a=0
$b=0
$c=0
HotKeySet($Exitkey, '_Exit')

While 1
    Do
        ConsoleWrite("MouseClicks, $a = " & $a & @LF)
        $a=$a+1
        Sleep(500)
    Until $a=10
    If $a=10 Then
        Do
            ConsoleWrite("More MouseClicks, $b = " & $b & @LF)
            $b=$b+1
            Sleep(500)
        Until $b=1
    EndIf
    If $b=1 Then
        Do
            ConsoleWrite("Even More MouseClicks, $c = " & $c & @LF)
            $c=$c+1
            Sleep(500)
        Until $c=10
    EndIf
    If $c=10 Then
        $c = 0
        Do
            ConsoleWrite("And Even More MouseClicks, $c = " & $c  & @LF)
            $c=$c+1
            Sleep(500)
        Until $c=1
    EndIf
    $a=0
    $b=0
    $c=0
WEnd

Func _Exit()
    Exit
EndFunc

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Try this. I've slightly modified your script, mostly just added indents, but I did add/change code a bit too. If this does what you want, compare it to your script to see the changes I've made.

$ExitKey="{ESC}"
$a=0
$b=0
$c=0
HotKeySet($Exitkey, '_Exit')

While 1
    Do
        ConsoleWrite("MouseClicks, $a = " & $a & @LF)
        $a=$a+1
        Sleep(500)
    Until $a=10
    If $a=10 Then
        Do
            ConsoleWrite("More MouseClicks, $b = " & $b & @LF)
            $b=$b+1
            Sleep(500)
        Until $b=1
    EndIf
    If $b=1 Then
        Do
            ConsoleWrite("Even More MouseClicks, $c = " & $c & @LF)
            $c=$c+1
            Sleep(500)
        Until $c=10
    EndIf
    If $c=10 Then
        $c = 0
        Do
            ConsoleWrite("And Even More MouseClicks, $c = " & $c  & @LF)
            $c=$c+1
            Sleep(500)
        Until $c=1
    EndIf
    $a=0
    $b=0
    $c=0
WEnd

Func _Exit()
    Exit
EndFunc

Alright well I looked at your code and tried working it in to what I understand.The console command is beyond me at the moment and since there are 6 distinct mouse movements and clicks for each section, but when I set it up close to what you have I quickly develop errors when I check it with the SyntaxProd, the EndIf's seem to cut off the While and it no longer recognizes the hotkey exit function either (and adding the indents does make it easier to read)

$ExitKey="{ESC}"
$a=0
$b=0
$c=0
HotKeySet($Exitkey, '_Exit');
    
Sleep(5000);
    
While 1   ;//THis makes the whole thing loop untill stopped
    Do
        MouseClick("left",317,159,3,0); 
        Sleep(1000);
        MouseClick("left",592,379,1,0);
        sleep(500);
        MouseClick("left",598, 465,1,0); 
        Sleep(500);
        MouseClick("left", 459,297,1,0); 
        Sleep(500);
        MouseClick("left", 377,471,1,0); 
        sleep(6000);
        MouseClick("left",560,357,1,0); 
        Sleep(500);
        $a=$a+1
    Until $a=3
    EndIf
    If $a=3 Then
        Do
            MouseClick("left",163,616,1,0); 
            send("/auto{ENTER}");
            sleep(500);
            MouseClick("left",372,321,1,0); 
            sleep(500)
            MouseClick("left",565,539,1,0);
            Sleep(26000);
            MouseClick("left",135,624,1,0); 
            sleep(500);
            Send("/auto{ENTER}"); 
            sleep(500);
            MouseClick("left",361,306,1,0);
            sleep(500);
            MouseClick("left",565,539,1,0);
            Sleep(13000);
            MouseClick("left",291,122,3,0); 
            Sleep(1000);
            MouseClick("left",499,107,1,0); 
            Sleep(500);
            $b=$b+1
        Until $b=1
    EndIf
    If $b=1 Then
        Do
            MouseClick("left",514,489,1,0); 
            Sleep(500);
            MouseClick("left",542,365,1,0); 
            Sleep(500);
            $c=$c+1
        Until $c=3
    EndIf
    If $c=3 Then
        Do   ;
            MouseClick("left",163,488,1,0);
            Sleep(500);
            MouseClick("left",131,622,1,0);
            Sleep(500);
            Send("/auto{ENTER}"); //WP2.1
            Sleep(500);
            MouseClick("left",370,354,1,0);
            sleep(500);
            Mouseclick("left",565,536,1,0);
            sleep(8000);
            MouseClick("left",131,622,1,0);
            Sleep(500);
            Send("/auto{ENTER}"); //WP2.2
            sleep(500);
            MouseClick("left",372,386,1,0);
            Sleep(500);
            MouseClick("left",564,539,1,0);
            Sleep(9500);
            MouseClick("left",131,622,1,0);
            Sleep(500);
            Send("/auto{ENTER}"); //WP2.3
            MouseClick("left",376,402,1,0);
            Sleep(500);
            MouseClick("left",564,539,1,0);
            sleep(12500);
            MouseClick("left",131,622,1,0);
            Sleep(500);
            Send("/auto{ENTER}"); //WP2.4
            MouseClick("left",373,418,1,0);
            Sleep(500);
            MouseClick("left",564,539,1,0);
            sleep(20600);
            MouseClick("left",131,622,1,0);
            Sleep(500);
            Send("/auto{ENTER}"); //WF
            MouseClick("left",376,290,1,0);
            Sleep(500);
            MouseClick("left",564,539,1,0);
            sleep(8500);
            $c=$c+1
        Until $c=1
    EndIf
    $a=0
    $b=0
    $c=0
WEnd
Func _Exit()
        Exit
EndFunc
Edited by SilvaDreams

Share this post


Link to post
Share on other sites

I just replaced all the mouseclicks, sleeps, and sends with ConsoleWrite, so I could run the script on my machine. They don't have to be in the final script. Run my script as it is and see if it is doing what you want.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

I just replaced all the mouseclicks, sleeps, and sends with ConsoleWrite, so I could run the script on my machine. They don't have to be in the final script. Run my script as it is and see if it is doing what you want.

Sorry about the slow response but family called, they always love to talk for a while.

As for the code I replaced the ConsoleWrite with my mouse click code and it still just loops back as if the variables are staying at their added amount and skipping over the first part of code and starting part way through.

I never thought this little problem would be so hard to nip in the rear..

Share this post


Link to post
Share on other sites

I've eyed this thing all night and even some this morning while looking back over examples and I still can't figure out why these variables won't revert back to 0 after the script runs through and starts back at a mid-point completely ignoring the first half of the code... I'll even mark in the script where it loops back to after making one full run.

$ExitKey="{ESC}"
$a=0
$b=0
$c=0
HotKeySet($Exitkey, '_Exit')

While 1
    Do
        MouseClick("left",317,159,3,0); 
        Sleep(1000);
        MouseClick("left",592,379,1,0);
        sleep(500);
        MouseClick("left",598, 465,1,0); 
        Sleep(500);
        MouseClick("left", 459,297,1,0); 
        Sleep(500);
        MouseClick("left", 377,471,1,0); 
        sleep(6000);
        MouseClick("left",560,357,1,0); 
        Sleep(500)
        $a=$a+1
        Sleep(500)
    Until $a=3
    If $a=3 Then
        Do
            MouseClick("left",163,616,1,0); //The code after running through once seems to start back here instead of all over
            send("/auto{ENTER}");
            sleep(500);
            MouseClick("left",372,321,1,0); 
            sleep(500)
            MouseClick("left",565,539,1,0);
            Sleep(26000);
            MouseClick("left",135,624,1,0); 
            sleep(500);
            Send("/auto{ENTER}"); 
            sleep(500);
            MouseClick("left",361,306,1,0);
            sleep(500);
            MouseClick("left",565,539,1,0);
            Sleep(13000);
            MouseClick("left",291,122,3,0); 
            Sleep(1000);
            MouseClick("left",499,107,1,0); 
            Sleep(500);
            $b=$b+1
            Sleep(500)
        Until $b=1
    EndIf
    If $b=1 Then
        Do
            MouseClick("left",514,489,1,0); 
            Sleep(500);
            MouseClick("left",542,365,1,0); 
            Sleep(500);
            $c=$c+1
            Sleep(500)
        Until $c=3
    EndIf
    If $c=3 Then
        Do
            MouseClick("left",163,488,1,0);
            Sleep(500);
            MouseClick("left",131,622,1,0);
            Sleep(500);
            Send("/auto{ENTER}"); 
            Sleep(500);
            MouseClick("left",370,354,1,0);
            sleep(500);
            Mouseclick("left",565,536,1,0);
            sleep(8000);
            MouseClick("left",131,622,1,0);
            Sleep(500);
            Send("/auto{ENTER}"); 
            sleep(500);
            MouseClick("left",372,386,1,0);
            Sleep(500);
            MouseClick("left",564,539,1,0);
            Sleep(9500);
            MouseClick("left",131,622,1,0);
            Sleep(500);
            Send("/auto{ENTER}"); 
            MouseClick("left",376,402,1,0);
            Sleep(500);
            MouseClick("left",564,539,1,0);
            sleep(12500);
            MouseClick("left",131,622,1,0);
            Sleep(500);
            Send("/auto{ENTER}"); 
            MouseClick("left",373,418,1,0);
            Sleep(500);
            MouseClick("left",564,539,1,0);
            sleep(20600);
            MouseClick("left",131,622,1,0);
            Sleep(500);
            Send("/auto{ENTER}"); 
            MouseClick("left",376,290,1,0);
            Sleep(500);
            MouseClick("left",564,539,1,0);
            sleep(8500);
            $c=$c+1
            Sleep(500)
        Until $c=1
    EndIf
    If  $a>=1   Then    $a=0
    If  $b>=1   Then    $b=0
    If  $c>=1   Then    $c=0
WEnd

Func _Exit()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

The last DoUntil loop will not end because $c is 3 to begin with, increments up each loop, and must equal 1 for the loop to end.So add <i><b>$c=0</b></i> as the first line in that loop, after the <b>Then</b>.<br><pre><a href="../../../autoit3/docs/keywords.htm"><span class="kw1"></span></a><br></pre><br>

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Alright so I think I understand, though wouldn't every variable need to be edited like that so it wouldn't loopback?

Until $c=10
    EndIf
    If $c=10 Then
        $c=0
        Do

I'm guessing this is what you ment (seeing as forum code went wonky on you)

Share this post


Link to post
Share on other sites

Alright so I think I understand, though wouldn't every variable need to be edited like that so it wouldn't loopback?

Until $c=10
    EndIf
    If $c=10 Then
        $c=0
        Do

I'm guessing this is what you ment (seeing as forum code went wonky on you)

Actually I tested it out and did what I had asked and yep, my code now works flawlessly, it no longer loops back on itself and cycles through it's intended cycles as I wanted it to... Now to move onto trying to implement other things.

Share this post


Link to post
Share on other sites

I'm glad you got it going, and yeah, that is what I meant. I edited my post to add some text, and.. the wonkiness began..


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
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
Sign in to follow this  
Followers 0