Sign in to follow this  
Followers 0
SmokeyDaBears

Help with Looping a script

12 posts in this topic

I'm no autoIT genius. I've been able to hoble my way around this script. It works perfectly for what I want it to do. My problem now is, I wanna add one more function. I want the whole script to loop a certain amount times that I enter, then output 1 keystroke, then terminate the script. Hopefully someone can help. Thanks.

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
Opt("MouseClickDragDelay", 100)

Sleep("5000")
$i = 0
$var1 = "1"
$var2 = "10"
$var3 = "57" 
$var4 = "88" 
$var5 = "818" 
$var6 = "514" 
$var7 = "754"
$var8 = "512" 
$var9 = "268" 
$var10 = "478" 
$var11 = "685" 
$var12 = "504" 
$var13 = "889" 
$var14 = "515" 
$var15 = "570" 
$var16 = "522" 
$var17 = "69" 
$var18 = "618" 

Do
If $i = 0 Then
   For $x = 1 to $var1
       Sleep ("1000")
   MouseClick ( "right" , $var3, $var4, 1 )
        Sleep("2000")
        Send("1")
        Sleep("2000")
    Next
    For $x = 1 to $var2
        MouseClickDrag ( "left" , $var5, $var6, $var7, $var8, 1)
        Sleep("500")
        MouseClick ( "right" , $var11, $var12, 1 )
        Sleep("2000")
        Send("5")
        Sleep("2000")
        MouseClickDrag ( "left" , $var5, $var6, $var7, $var8, 1)
        Sleep("500")
        MouseClick ( "right" , $var9, $var10, 1 )
        Sleep("2000")
        Send("1")
        Sleep("1000")
        MouseClick ( "right" , $var7, $var8, 1 )
        Sleep("1000")
        Send("6")
        Sleep("2000")
        MouseClickDrag ( "left" , $var13, $var14, $var5, $var6, 1)
        Sleep("1000")
        MouseClick ( "left" , $var15, $var16, 1 )
        Sleep("1000")
        MouseClickDrag ( "left" , $var5, $var6, $var7, $var8, 1)
        Sleep("1000")
        MouseClick ( "right" , $var7, $var8, 1 )
        Sleep("1000")
        Send("5")
        Sleep("1000")
    Next
    MouseClickDrag ( "left" , $var5, $var6, $var17, $var18, 1)
        EndIf
   
Until $i = 1
Exit 0

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Share this post


Link to post
Share on other sites



While 1

script here

WEnd

Loop...and for exiting you want

Hotkeyset("{f1}", "Exit")

Func exit()

Exit

EndFunc

is that what your asking?

Share this post


Link to post
Share on other sites

Say I want the script in between

Do

...

and EndIf

to run 50 times. Then I want it to press 7, then terminate the script.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You can't do: DO and Endif.

Edited by JustinReno

Share this post


Link to post
Share on other sites

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
Opt("MouseClickDragDelay", 100)

Sleep("5000")
$i = 0
$var1 = "1"
$var2 = "10"
$var3 = "57" 
$var4 = "88" 
$var5 = "818" 
$var6 = "514" 
$var7 = "754"
$var8 = "512" 
$var9 = "268" 
$var10 = "478" 
$var11 = "685" 
$var12 = "504" 
$var13 = "889" 
$var14 = "515" 
$var15 = "570" 
$var16 = "522" 
$var17 = "69" 
$var18 = "618" 

While 1
Do
If $i = 0 Then
   For $x = 1 to $var1
       Sleep ("1000")
   MouseClick ( "right" , $var3, $var4, 1 )
        Sleep("2000")
        Send("1")
        Sleep("2000")
    Next
    For $x = 1 to $var2
        MouseClickDrag ( "left" , $var5, $var6, $var7, $var8, 1)
        Sleep("500")
        MouseClick ( "right" , $var11, $var12, 1 )
        Sleep("2000")
        Send("5")
        Sleep("2000")
        MouseClickDrag ( "left" , $var5, $var6, $var7, $var8, 1)
        Sleep("500")
        MouseClick ( "right" , $var9, $var10, 1 )
        Sleep("2000")
        Send("1")
        Sleep("1000")
        MouseClick ( "right" , $var7, $var8, 1 )
        Sleep("1000")
        Send("6")
        Sleep("2000")
        MouseClickDrag ( "left" , $var13, $var14, $var5, $var6, 1)
        Sleep("1000")
        MouseClick ( "left" , $var15, $var16, 1 )
        Sleep("1000")
        MouseClickDrag ( "left" , $var5, $var6, $var7, $var8, 1)
        Sleep("1000")
        MouseClick ( "right" , $var7, $var8, 1 )
        Sleep("1000")
        Send("5")
        Sleep("1000")
    Next
    MouseClickDrag ( "left" , $var5, $var6, $var17, $var18, 1)
        EndIf
WEnd
   
Until $i = 1
Exit 0

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 
EndFunc

Share this post


Link to post
Share on other sites

afkreloop.au3(67,1) : ERROR: missing Until <expr>.

Share this post


Link to post
Share on other sites

afkreloop.au3(67,1) : ERROR: missing Until <expr>.

Move the Until $i = 1 above the Wend

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Here's current script. Still endlessly loops.

HotKeySet("{ESC}", "Terminate")
Opt("MouseClickDragDelay", 100)

Sleep("5000")
$i = 0
$var1 = "1"
$var2 = "1"
$var3 = "57"
$var4 = "88"
$var5 = "818"
$var6 = "514"
$var7 = "754"
$var8 = "512"
$var9 = "268"
$var10 = "478"
$var11 = "685"
$var12 = "504"
$var13 = "889"
$var14 = "515"
$var15 = "570"
$var16 = "522"
$var17 = "69"
$var18 = "618"

While 1
Do
If $i = 0 Then
   For $x = 1 to $var1
       Sleep ("1000")
   MouseClick ( "right" , $var3, $var4, 1 )
        Sleep("2000")
        Send("1")
        Sleep("2000")
    Next
    For $x = 1 to $var2
        MouseClickDrag ( "left" , $var5, $var6, $var7, $var8, 1)
        Sleep("500")
        MouseClick ( "right" , $var11, $var12, 1 )
        Sleep("2000")
        Send("5")
        Sleep("2000")
        MouseClickDrag ( "left" , $var5, $var6, $var7, $var8, 1)
        Sleep("500")
        MouseClick ( "right" , $var9, $var10, 1 )
        Sleep("2000")
        Send("1")
        Sleep("1000")
        MouseClick ( "right" , $var7, $var8, 1 )
        Sleep("1000")
        Send("6")
        Sleep("2000")
        MouseClickDrag ( "left" , $var13, $var14, $var5, $var6, 1)
        Sleep("1000")
        MouseClick ( "left" , $var15, $var16, 1 )
        Sleep("1000")
        MouseClickDrag ( "left" , $var5, $var6, $var7, $var8, 1)
        Sleep("1000")
        MouseClick ( "right" , $var7, $var8, 1 )
        Sleep("1000")
        Send("5")
        Sleep("1000")
    Next
    MouseClickDrag ( "left" , $var5, $var6, $var17, $var18, 1)
        EndIf
Until $i = 1
WEnd
  Exit


Func Terminate()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

Sure it will. There is no place (that I see) inside the loop where $i gets changed so it remains 0 and you told it not to exit the loop until it's 1. You can either change the value of $i someplace in the loop or add an ExitLoop statement where you want it to exit.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

I'm not that smart.

I added an $i = 0 + 1

after the last MouseClickDrag, but I dont know where to tell it when $i = 20 or however many times I want it to loop, to exit script.

Share this post


Link to post
Share on other sites

HotKeySet("{ESC}", "Terminate")
Opt("MouseClickDragDelay", 100)

Sleep("5000")
$i = 0
$var1 = "1"
$var2 = "1"
$var3 = "57"
$var4 = "88"
$var5 = "818"
$var6 = "514"
$var7 = "754"
$var8 = "512"
$var9 = "268"
$var10 = "478"
$var11 = "685"
$var12 = "504"
$var13 = "889"
$var14 = "515"
$var15 = "570"
$var16 = "522"
$var17 = "69"
$var18 = "618"

Do
   For $x = 1 to $var1
       Sleep ("1000")
   MouseClick ( "right" , $var3, $var4, 1 )
        Sleep("2000")
        Send("1")
        Sleep("2000")
    Next
    For $x = 1 to $var2
        MouseClickDrag ( "left" , $var5, $var6, $var7, $var8, 1)
        Sleep("500")
        MouseClick ( "right" , $var11, $var12, 1 )
        Sleep("2000")
        Send("5")
        Sleep("2000")
        MouseClickDrag ( "left" , $var5, $var6, $var7, $var8, 1)
        Sleep("500")
        MouseClick ( "right" , $var9, $var10, 1 )
        Sleep("2000")
        Send("1")
        Sleep("1000")
        MouseClick ( "right" , $var7, $var8, 1 )
        Sleep("1000")
        Send("6")
        Sleep("2000")
        MouseClickDrag ( "left" , $var13, $var14, $var5, $var6, 1)
        Sleep("1000")
        MouseClick ( "left" , $var15, $var16, 1 )
        Sleep("1000")
        MouseClickDrag ( "left" , $var5, $var6, $var7, $var8, 1)
        Sleep("1000")
        MouseClick ( "right" , $var7, $var8, 1 )
        Sleep("1000")
        Send("5")
        Sleep("1000")
    Next
    MouseClickDrag ( "left" , $var5, $var6, $var17, $var18, 1)
    $i = $i + 1
Until $i = 50
Send("7")
Terminate()


Func Terminate()
    Exit
EndFunc

Will this help? I removed the for and while function and added a incrementation for $i and set the do function to repeat its self 51 times. Change the Until $i = 50 for more or less loops then just send the key 7 and terminate the script :)

Share this post


Link to post
Share on other sites

That did the trick! You ROCK! Thanks.

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