Jump to content

Basic autoit3 question


Recommended Posts

Generally this seems to work by reading the commands and running them in order. What I need to do is run two commands at once or basically multiple processes. Is it possible to do with autoit?

Basically for a example, I have this overall function, and in that function I might have sleep commands in one part of the function that deals with certain things. Is it possible to split that function so I can start another function in that while starting my function with my sleep commands. I'm looking to save time instead of waiting for my function with all my sleep commands to get done. You might ask why don't I just put that other part first. I need to run it multiple times while the other function is running which contains the sleep commands.

Could anyone point me in the right direction?

Link to comment
Share on other sites

; Color = #C61010
; spot1 765, 227 
; spot2 765, 246 
; spot3 765, 265 
; spot4 765, 284
; spot5 765, 303
; spot6 765, 322
; spot7 765, 341
; spot8 765, 360
; spot9 765, 379
; spot10 765, 398
; spot11 765, 417
; spot12 765, 436
; spot13 765, 455
; spot14 765, 474
; spot15 765, 493
; spot16 765, 512
Func Target ()
    $coord = PixelSearch( 765, 265, 765, 265, 0xC61010, 10 )
If Not @error Then
    MouseClick ( "left", $coord[0], $coord[1], 1, 1 ); click1
    Sleep( 500 )
    MouseClick ( "left", 910, 125, 1, 1 ); click2
    ToolTip( "X and Y are:", 0,50, $coord[0] & "," & $coord[1])
    Sleep( 500 )
Else 
    ToolTip( "color not found",0,50)
    Sleep( 500 )
EndIf
$coord = PixelSearch( 765, 284, 765, 284, 0xC61010, 10 )
If Not @error Then
    MouseClick ( "left", $coord[0], $coord[1], 1, 1 ); click1
    Sleep( 500 )
    MouseClick ( "left", 910, 125, 1, 1 ); click2
    ToolTip( "X and Y are:", 0,50, $coord[0] & "," & $coord[1])
    Sleep( 500 )
Else 
    ToolTip( "color not found",0,50)
    Sleep( 500 )
EndIf
EndFunc

Call( "Target" )

So multiple things. Right now I know there is probably a easier way than pasting like 17 spots to color find in a row. But I'll deal with that later. So I have this one function which finds colors. Right now it looks for the first color in spot1. Then does stuff if it doesn't find it it moves down to the second. Then it does the stuff for spot2 etc etc up to 17 times in the end. I haven't yet written the next function but what it needs to do is search a different part of the screen while this function is running. Basically I really do need to run multiple color searches at the same time. If that means double clicking on two .au3 files and have them run at the same time I guess that's what I'll have to do. However I would prefer to have multiple color finds going on at the same time rather than just doing run1 run2 run3 run4 run5. This is just in the starting stages for me. I need to make sure I don't get stuck in a place where one of my functions takes 30 seconds to complete and nothing happens until that's done.

Edit: While I might have your attention, do you know if using that $coord belongs to each of those colorfinds. Or will I have problems if I run two functions which use $coord. I don't want my values to return incorrect if I run two functions which use $coord at the same time.

Edited by forgetoo
Link to comment
Share on other sites

Have this script act as your control script, and have it launch (repeatedly) a second compiled script. Look at the Run or ShellExecute commands in the help file. Each script will have it own process and memory, so a variable defined in script a, will not be 'walked-on' by a variable of the same name in script b. I assume you'll want to pass a couple parameters to the called script, so search on CmdLine in the help file.

Edited by Spiff59
Link to comment
Share on other sites

This would be my second script then. Thanks for that info. Now is there a easy way to pass the x,y values to keep me from pasting that same if else statement 17 times? I was thinking a array from reading, but I really don't have any idea if that's correct or even what I would want to use.

Edited by forgetoo
Link to comment
Share on other sites

Lots of ways, here's one...

Global $Color = 0xC61010
Global $Spot[16][2] = [[765, 227],[765, 246],[765, 265],[765, 284],[765, 303],[765, 322],[765, 341],[765, 360], _
                     [765, 379],[765, 398],[765, 417],[765, 436],[765, 455],[765, 474],[765, 493],[765, 512]]
                     
Target()

Func Target ()
    For $x = 0 to 15
        $coord = PixelSearch($Spot[$x][0], $Spot[$x][1], $Spot[$x][0], $Spot[$x][1], $Color, 10 )
        If Not @error Then
;       If PixelGetColor($Spot[$x][0], $Spot[$x][1]) = $Color Then
            MouseClick ( "left", $coord[0], $coord[1], 1, 1 ); click1
            Sleep( 500 )
            MouseClick ( "left", 910, 125, 1, 1 ); click2
            ToolTip( "X and Y are:", 0,50, $coord[0] & "," & $coord[1])
        Else 
            ToolTip( "color not found",0,50)
        EndIf
        Sleep( 500 )
    Next
EndFunc

Edit: If you only need to check for that exact color value, then the commented-out PixelGetColor line above I believe is considerably faster than PixelSearch

Edited by Spiff59
Link to comment
Share on other sites

Sadly no. I already thought of doing a defined color but it might be off by about 10%. Which is why I figured I would have to use the PixelSeach. I checked PixelGetColor but it doesn't allow for the error in color that I need. To speed this up I've limited to basically one pixel on the screen per search.

Thanks for the above though, I'll modify that a bit but the general idea will work good for saving extra lines of code.

Edited by forgetoo
Link to comment
Share on other sites

Quick question from the above to make sure I understand whats going

onGlobal $Spot[16][2] = [[765, 227],[765, 246],[765, 265],[765, 284],[765, 303],[765, 322],[765, 341],[765, 360], _
                     [765, 379],[765, 398],[765, 417],[765, 436],[765, 455],[765, 474],[765, 493],[765, 512]]

the [16] is 16 things basically.. and the [2] denotes two fields, in my case x,y cords?

$coord = PixelSearch($Spot[$x][0], $Spot[$x][1], $Spot[$x][0], $Spot[$x][1], $Color, 10 )

and if I later needed to do more than a one pixel search would this change to

PixelSearch($Spot[$x][0], $Spot[$x][1], $Spot[$x][3], $Spot[$x][4], $Color, 10 ) ?

with the above being like

onGlobal $Spot[16][4] = [[765, 227, 123, 154],[765, 246, 253, 684],etc etc etc

Link to comment
Share on other sites

Quick question from the above to make sure I understand whats going

onGlobal $Spot[16][2] = [[765, 227],[765, 246],[765, 265],[765, 284],[765, 303],[765, 322],[765, 341],[765, 360], _
                     [765, 379],[765, 398],[765, 417],[765, 436],[765, 455],[765, 474],[765, 493],[765, 512]]

the [16] is 16 things basically.. and the [2] denotes two fields, in my case x,y cords?

Yeppers, it declares a 16x2 0-based array. The first x value would be $Spot[0][0] and the 16th y is $Spot[15][1].

$coord = PixelSearch($Spot[$x][0], $Spot[$x][1], $Spot[$x][0], $Spot[$x][1], $Color, 10 )

and if I later needed to do more than a one pixel search would this change to

PixelSearch($Spot[$x][0], $Spot[$x][1], $Spot[$x][3], $Spot[$x][4], $Color, 10 ) ?

with the above being like

onGlobal $Spot[16][4] = [[765, 227, 123, 154],[765, 246, 253, 684],etc etc etc

Am betting you just typo'ed it, but since the arrays here are 0-based, the next two elements would be 2 and 3, not 3 and 4.
Link to comment
Share on other sites

Someone tell me if this is correct. I've got another set of things to check and this time its 3 different hex colors. So I need to check each of the 16 spots with each of the 3 colors. From looking at the above I've figured this. But I'd like to know if this is what it should look like.

Global $FriendlyColor[3][1] = [[0x7321B5],[0x042177],[0x107310]]
Global $FSpot[16][2] = [[775, 229],[775, 248],[775, 267],[775, 286],[775, 305],[775, 324],[775, 343],[775, 362], _
                     [775, 381],[775, 400],[775, 419],[775, 438],[775, 457],[775, 476],[775, 495],[775, 514]]

Func Check1 () 
    For $y = 0 to 2
    For $x = 0 to 15
        $coord = PixelSearch($FSpot[$x][0], $FSpot[$x][1], $FSpot[$x][0], $FSpot[$x][1], $FriendlyColor[$y][0], 10 )
        If Not @error Then
            Call ( func4 )
        Else
            Call ( func5 )
        EndIf
    Next
EndFunc
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...