Jump to content

How to Loop 10 times then do an action then restart the thing to loop ?


Valara
 Share

Recommended Posts

Hello i'm new there and i'm learning how to use autoit, i'm trying to do a macro for crafting in a game : there is what i have currently;

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

Sleep (5000) 

While 1 
; Action 1:
MouseClickDrag ( "left" , 1150, 350, 1025, 350, 3) 
Sleep (500)
; Action 2:
MouseClick ( "right" , 1090, 350, 1 ) 
Sleep (500) 
MouseClick ( "left" , 1090, 410, 1 ) 
Sleep (500) 
;Action 3: 
MouseClickDrag ( "left" , 1150, 350, 1025, 350, 3) 
Sleep (500) 
;Action 4: 
MouseClick ( "left" , 150, 150, 3 ) 
Sleep (300) 
;Action 5: 
MouseClick ( "right" , 1025, 350, 1 ) 
Sleep (500) 
MouseClick ( "left" , 930, 400, 1 ) 
Sleep (500) 
;Action 6: 
MouseClickDrag ( "left" , 1229, 338, 1150, 350, 3) 
Sleep (500) 
;Action 7: 
MouseClick ( "left" , 750, 530, 1)  
Sleep (500) 
;Action 8: 
MouseClickDrag ( "left" , 1150, 350, 1025, 350, 3) 
Sleep (500) 
;Action 9: 
MouseClick ( "right" , 1024, 350, 1 )  
Sleep (500) 
MouseClick ( "left" , 1026, 417, 1)
Sleep (500) 
WEnd 


Func Terminate() 
    Exit 0 
EndFunc

I would like to repeat action 1 to 9 , 10 times then make a new action ( put the item done by action somewhere and take a new one to upgrade, this is something i will add after ), and repeat this all the time.

Resume : 10 times action 1 to 9, then 1 time action 10 ,then repeat all. Do you have an idea how i could do that please ?

Edited by Valara
Link to comment
Share on other sites

Global $Paused, $ShowMe, $Count = 0

Opt("MouseClickDragDelay", 100)

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F9}", "ShowMe")

Sleep(5000)

While 1
    
    If $ShowMe And $Count <= 10 Then
        ; Action 1:
        MouseClickDrag("left", 1150, 350, 1025, 350, 3)
        Sleep(500)
        ; Action 2:
        MouseClick("right", 1090, 350, 1)
        Sleep(500)
        MouseClick("left", 1090, 410, 1)
        Sleep(500)
        ;Action 3:
        MouseClickDrag("left", 1150, 350, 1025, 350, 3)
        Sleep(500)
        ;Action 4:
        MouseClick("left", 150, 150, 3)
        Sleep(300)
        ;Action 5:
        MouseClick("right", 1025, 350, 1)
        Sleep(500)
        MouseClick("left", 930, 400, 1)
        Sleep(500)
        ;Action 6:
        MouseClickDrag("left", 1229, 338, 1150, 350, 3)
        Sleep(500)
        ;Action 7:
        MouseClick("left", 750, 530, 1)
        Sleep(500)
        ;Action 8:
        MouseClickDrag("left", 1150, 350, 1025, 350, 3)
        Sleep(500)
        ;Action 9:
        MouseClick("right", 1024, 350, 1)
        Sleep(500)
        MouseClick("left", 1026, 417, 1)
        Sleep(500)
        $Count += 1
        
        If $Count = 10 Then
            ; do this
            ; and this
        EndIf
        
    EndIf
    Sleep(20)
WEnd

Func ShowMe()
    $ShowMe = Not $ShowMe
    $Count = 0
EndFunc   ;==>ShowMe

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Global $Paused, $ShowMe, $Count = 0

Opt("MouseClickDragDelay", 100)

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F9}", "ShowMe")

Sleep(5000)

While 1
    
    If $ShowMe And $Count < 10 Then
        ; Action 1:
        MouseClickDrag("left", 1150, 350, 1025, 350, 3)
        Sleep(500)
        ; Action 2:
        MouseClick("right", 1090, 350, 1)
        Sleep(500)
        MouseClick("left", 1090, 410, 1)
        Sleep(500)
        ;Action 3:
        MouseClickDrag("left", 1150, 350, 1025, 350, 3)
        Sleep(500)
        ;Action 4:
        MouseClick("left", 150, 150, 3)
        Sleep(300)
        ;Action 5:
        MouseClick("right", 1025, 350, 1)
        Sleep(500)
        MouseClick("left", 930, 400, 1)
        Sleep(500)
        ;Action 6:
        MouseClickDrag("left", 1229, 338, 1150, 350, 3)
        Sleep(500)
        ;Action 7:
        MouseClick("left", 750, 530, 1)
        Sleep(500)
        ;Action 8:
        MouseClickDrag("left", 1150, 350, 1025, 350, 3)
        Sleep(500)
        ;Action 9:
        MouseClick("right", 1024, 350, 1)
        Sleep(500)
        MouseClick("left", 1026, 417, 1)
        Sleep(500)
        $Count += 1
    EndIf
    Sleep(20)
WEnd

Func ShowMe()
    $ShowMe = Not $ShowMe
    $Count = 0
EndFunc   ;==>ShowMe

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

8)

thanks you a lot i will try this and try the link you gave 1-2-3 autoit for dummies :) happy xmass

Link to comment
Share on other sites

Welcome!!

... there was a slight change as you posted, copy/use the latest one

8)

Work perfect except that the macro after action 10 and 11 restart 1 to 9 only one time, maybe i did something wrong i would it to continue to repeat 1 to 9, 10 times again.

There is the new script :

Global $Paused, $Showme, $Count = 0 
HotKeySet("{ESC}", "Terminate")
HotKeySet("{F9}", "ShowMe")
Opt("MouseClickDragDelay", 100) 
WinActivate( "Star Wars Galaxies", "")
Sleep (5000) 


While 1 
    If $ShowMe And $Count <= 10 Then
; Action 1:
MouseClickDrag ( "left" , 1150, 350, 1025, 350, 3)  
Sleep (500)
;Action 2: 
MouseClick ( "right" , 1090, 350, 1 ) 
Sleep (500) 
MouseClick ( "left" , 1090, 410, 1 ) 
Sleep (500) 
;Action 3: 
MouseClickDrag ( "left" , 1150, 350, 1025, 350, 3) 
Sleep (500) 
;Action 4: 
MouseClick ( "left" , 150, 150, 3 ) 
Sleep (300) 
;Action 5: 
MouseClick ( "right" , 1025, 350, 1 )  
Sleep (500) 
MouseClick ( "left" , 930, 400, 1 )  
Sleep (500) 
;Action 6: 
MouseClickDrag ( "left" , 1229, 338, 1150, 350, 3) 
Sleep (500) 
;Action 7:
MouseClick ( "left" , 750, 530, 1)  
Sleep (500) 
;Action 8: 
MouseClickDrag ( "left" , 1150, 350, 1025, 350, 3) 
Sleep (500) 
;Action 9: 
MouseClick ( "right" , 1024, 350, 1 )  
Sleep (500) 
MouseClick ( "left" , 1026, 417, 1)  
Sleep (500) 
$Count += 1
        
        If $Count = 10 Then
            MouseClickDrag ( "left" , 1150, 350, 1219, 955, 3); Action 10 
                                                Sleep (500)
            MouseClickDrag ( "left" , 829, 887, 1150, 350, 3); Action 11
                                                Sleep (500)
        
        EndIf
        
    EndIf
    Sleep(20)
WEnd

Func ShowMe()
    $ShowMe = Not $ShowMe
    $Count = 0
EndFunc  ;==>ShowMe

Func Terminate()
    Exit 0
EndFunc  ;==>Terminate
Link to comment
Share on other sites

Just add one line here..

If $Count = 10 Then

MouseClickDrag ( "left" , 1150, 350, 1219, 955, 3); Action 10

Sleep (500)

MouseClickDrag ( "left" , 829, 887, 1150, 350, 3); Action 11

Sleep (500)

$Count = 0 ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Right here

EndIf

and it will keep going untill you press F9 to stop it

8)

NEWHeader1.png

Link to comment
Share on other sites

Just add one line here..

If $Count = 10 Then

MouseClickDrag ( "left" , 1150, 350, 1219, 955, 3); Action 10

Sleep (500)

MouseClickDrag ( "left" , 829, 887, 1150, 350, 3); Action 11

Sleep (500)

$Count = 0 ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Right here

EndIf

and it will keep going untill you press F9 to stop it

8)

thank you again :) this work fine :P:blink:

Link to comment
Share on other sites

thank you again :) this work fine :P:blink:

I'm wondering if there is a way to end this script after a set amount of time as well.

So the script runs 10 times, then does the added steps and then goes back to running main steps 10 times, and it continues this pattern for X number of minutes.

Is this possible?

-Tim

Link to comment
Share on other sites

You have some sort of While loop (haven't read it)

So:

$time = TimerInit()
While 1
  Sleep(25) ;do some actions, I just put a Sleep() in there for testing purposes
  If TimerDiff($time) > 5000 Then Exit ;this is 5 seconds (x * 60000 = x minutes)
WEnd

That works really well, thanks.

I do have a little more indepth questions if you have time. Looking at the first script it has ability to excute a few parts of this script a set number of times and now contine to work for a set amount of time.

Is it possible to to add a pop up window that would ask for the number of times to do that part of the script and also ask how long it should run? This would let you modify this script with out recompliling each time you wanted to change either of those parts.

Thanks again.

This is what the script looks like now.

Global $Paused, $Showme, $Count = 0, $time = TimerInit()
HotKeySet("{ESC}", "Terminate")
HotKeySet("{F9}", "ShowMe")
Opt("MouseClickDragDelay", 100) 
WinActivate( "Star Wars Galaxies", "")
Sleep (5000) 


While 1 
    If TimerDiff($time) > 30000 Then Exit;(x * 60000 = x minutes)
    If $ShowMe And $Count <= 10 Then
While 1 
;a1 
MouseClickDrag ( "left" , XA, YA, XB, YB, 1)  
Sleep (700) 
;a2
MouseClick ( "right" , XC, YC, 1 )  
Sleep (500) 
MouseClick ( "right" , XD, YD, 1 )  
Sleep (1000) 
;a3: 
MouseClickDrag ( "left" , XA, YA, XB, YB, 1)
Sleep (700) 
;a4
MouseClick ( "left" , XE, YE, 3 )  
Sleep (500) 
;a4 
MouseClick ( "right" , XB, YB, 1 )  
Sleep (500) 
MouseClick ( "left" , XF, YF, 1 ) 
Sleep (1000) 
;a6 
MouseClickDrag ( "left" , XH, YH, XA, YA, 1) 
Sleep (700) 
;a7
MouseClick ( "left" , XG, YG, 1)  
Sleep (500) 
;a8 
MouseClickDrag ( "left" , XA, YA, XB, YB, 1) 
Sleep (700) 
;a9 
MouseClick ( "right" , XB, YB, 1 ) 
Sleep (500) 
MouseClick ( "left" , XI, YI, 1)  
Sleep (1000)
$Count += 1
        
        If $Count = 10 Then
        ;a10
            MouseClickDrag ( "left" , XA, YA, XJ, YJ, 3)
                                                Sleep (500)
        ;a11
            MouseClickDrag ( "left" , XK, YK, XL, YL, 3)
                                                Sleep (500)
        $Count = 0;
        EndIf
        
    EndIf
    Sleep(20)
WEnd

Func ShowMe()
    $ShowMe = Not $ShowMe
    $Count = 0
EndFunc ;==>ShowMe

Func Terminate()
    Exit 0
EndFunc ;==>Terminate
Edited by Cuervo

-Tim

Link to comment
Share on other sites

I know the script would need to variables, one is how many times to run before it executes the If $Count statement and how long to run in seconds before stopping.

The first part is the If $Count which would need to be insterted into the script in two locations and the second is the If TimerDiff($time) variable in seconds. Since 60000 is equal to one minuted it would have to convert the number of minutes into seconds pass that to the If TimerDiff($time) variable.

Anyway I know what I would like it to do, but I don't know how to do that.

-Tim

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...