Jump to content

Recommended Posts

Hey folks, it's been so much time since I still have this issue, I'm trynna make a script for a Identikit software that I made, we're talking about simple stuff.

I'm still new with Scripting in AutoIT and generally with Basic so please explain me how to solve the problem step by step.

Basically my script should recognise when I've choosed wrong or right with some images that pop up in my screen when I try to interact with my Identikit software.

this is the script:

https://pastebin.com/TjRs9FLu

and this is the Autocheck issue:

https://ibb.co/sJtTnZb

Thanks anyone for paying attention, I hope you guys can help me

Share this post


Link to post
Share on other sites

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Also:  Please post the script and other info simply in the post in a CodeBlock <> in stead of linking pastebin so people don't have to go to other sites to get all info. ;) 

Jos

Edited by Jos

Share this post


Link to post
Share on other sites

Hey folks, it's been so much time since I still have this issue, I'm trynna make a script for a Identikit software that I made, we're talking about simple stuff.

I'm still new with Scripting in AutoIT and generally with Basic so please explain me how to solve the problem step by step.

Basically my script should recognise when I've choosed wrong or right with some images that pop up in my screen when I try to interact with my Identikit software.

this is the script:

#include <AutoItConstants.au3>
#include "ImageSearch_64_bit/Imagesearch.au3"
#include <Misc.au3>
HotKeySet("{f1}", "myExit")
#AutoIt3Wrapper_UseX64=y
$x=0
$y=0

Global $Counter = 1

init(); changed all that to a function to call one time(  readability)

while 1
    $timer = timerinit()
    Do
        MouseClick("Left", 779, 600, 1, 2) ; Red
        sleep(500)
        MouseClick("Left", 896, 685, 1, 2)
        Call ( "myResult", $Counter )
        sleep(2000)
        MouseClick("Left", 607, 361, 1, 2) ;Blue
        sleep(500)
        MouseClick("Left", 896, 685, 1, 2)
        Call ( "myResult", $Counter )
        sleep(2000)
        MouseClick("Left", 779, 600, 1, 2) ;Red
        sleep(500)
        MouseClick("Left", 896, 685, 1, 2)
        Call ( "myResult", $Counter )
        sleep(2000)
        MouseClick("Left", 779, 600, 1, 2) ;Red
        sleep(500)
        MouseClick("Left", 896, 685, 1, 2)
        Call ( "myResult", $Counter )
        sleep(2000)
        MouseClick("Left", 607, 361, 1, 2) ;Blue
        sleep(500)
        MouseClick("Left", 896, 685, 1, 2)
        Call ( "myResult", $Counter )
        sleep(2000)
        MouseClick("Left", 607, 361, 1, 2) ;Blue
        sleep(500)
        MouseClick("Left", 896, 685, 1, 2)
        Call ( "myResult", $Counter )
        Sleep(2000)
    until timerdiff($timer) > 960;
WEnd


func myResult($Counter)
    ;ConsoleWrite(" Function myresult is called " & @CRLF)
    $Variable = _ImageSearch("quinto.bmp", 0, $x,$y,0) Or _ImageSearch("quarto.bmp", 0, $x,$y,0)
    If IsArray($Variable) = True Then
        ConsoleWrite(" Win is found " & @CRLF)
        MouseClick("Left", 1110, 684, 1, 1)
        MouseClick($MOUSE_CLICK_LEFT,  $Variable[0], $Variable[1], $Counter)
    Else
        $Variable = _ImageSearch("primo.bmp", 0,$x,$y,0) Or _ImageSearch("secondo.bmp", 0, $x,$y,0) Or _ImageSearch("terzo.bmp", 0, $x,$y,0)
        If IsArray($Variable) = True Then
            ConsoleWrite(" no win is found " & @CRLF)
            For $vElement In $Variable
                $Counter = $Counter * 2
            Next
            MouseClick($MOUSE_CLICK_LEFT, $Variable[0], $Variable[1], $Counter)
        EndIf
    EndIf
EndFunc

Func init()
    WinActivate("Identikit")
    WinWaitActive("Identikit", "", 10); wait for 10 sec to appear
    MouseClick("Left", 746, 666, 1, 1)
    sleep(4000)
    MouseWheel($MOUSE_WHEEL_DOWN, 7)
    sleep(500)
    MouseClick("Left", 350, 798, 1, 1)
    sleep(2000)
    MouseClick("Left", 1010, 712, 1, 1)
    sleep(16000)
    MouseWheel($MOUSE_WHEEL_DOWN, 1)
    sleep(1000)
EndFunc

func myExit()
    Exit
EndFunc

and I'll leave a picture with the Autocheck screenshot so you guys can see the error

anew.PNG

Share this post


Link to post
Share on other sites

Sorry to be a pain, but just stick to the one topic I already moved for you.

Jos

Share this post


Link to post
Share on other sites

@Polistotele

What application are you trying to automate?


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

Have you checked what statement is on line 44 of the Imagesearch.au3 include you use?

Jos

Share this post


Link to post
Share on other sites

Don't know what the reason is but guess some error checking is missing in that UDF.
I don't know that include as it isn't a standard include so do you have a link to the sourcecode so it can be checked why you get the error.

Jos

Share this post


Link to post
Share on other sites

please help me, this is the library

#include-once
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with Image Search
;                 Require that the ImageSearchDLL.dll be loadable
;
; ------------------------------------------------------------------------------

;===============================================================================
;
; Description:      Find the position of an image on the desktop
; Syntax:           _ImageSearchArea, _ImageSearch
; Parameter(s):
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
;
; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
;       a desktop region to search
;
;===============================================================================
Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance, $HBMP=0)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$HBMP)
EndFunc

Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance, $HBMP=0)
    ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
    if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
If IsString($findImage) Then
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
Else
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"ptr",$findImage,"ptr",$HBMP)
EndIf

    ; If error exit
    if $result[0]="0" then return 0

    ; Otherwise get the x,y location of the match and the size of the image to
    ; compute the centre of search
    $array = StringSplit($result[0],"|")

   $x=Int(Number($array[2]))
   $y=Int(Number($array[3]))
   if $resultPosition=1 then
      $x=$x + Int(Number($array[4])/2)
      $y=$y + Int(Number($array[5])/2)
   endif
   return 1
EndFunc

;===============================================================================
;
; Description:      Wait for a specified number of seconds for an image to appear
;
; Syntax:           _WaitForImageSearch, _WaitForImagesSearch
; Parameter(s):
;                   $waitSecs  - seconds to try and find the image
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImageSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance, $HBMP=0)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        sleep(100)
        $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance,$HBMP)
        if $result > 0 Then
            return 1
        EndIf
    WEnd
    return 0
EndFunc

;===============================================================================
;
; Description:      Wait for a specified number of seconds for any of a set of
;                   images to appear
;
; Syntax:           _WaitForImagesSearch
; Parameter(s):
;                   $waitSecs  - seconds to try and find the image
;                   $findImage - the ARRAY of images to locate on the desktop
;                              - ARRAY[0] is set to the number of images to loop through
;                                ARRAY[1] is the first image
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):  On Success - Returns the index of the successful find
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImagesSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance, $HBMP=0)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        for $i = 1 to $findImage[0]
            sleep(100)
            $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance,$HBMP)
            if $result > 0 Then
                return $i
            EndIf
        Next
    WEnd
    return 0
EndFunc

 

Share this post


Link to post
Share on other sites

If you look at help file for DllCall you would have notice that :

Return Value
Success: an array. See remarks. 
Failure: sets the @error flag to non-zero. 
@error: 1 = unable to use the DLL file,
2 = unknown "return type",
3 = "function" not found in the DLL file,
4 = bad number of parameters,
5 = bad parameter. 

$Result is not an array in case of failure.  It can be any of the errors mentioned. But my guess is you are not using the right (x86 vs x64) dll or the dll is missing (wrongly placed).

Edited by Nine

Share this post


Link to post
Share on other sites

I maybe mistaken, but how could ever the following test be True in Func myResult() when _ImageSearch() and _ImageSearchArea() Returns are only 0 or 1 ?

$Variable = _ImageSearch("quinto.bmp", 0, $x,$y,0) Or _ImageSearch("quarto.bmp", 0, $x,$y,0)
If IsArray($Variable) = True Then

 

Share this post


Link to post
Share on other sites
14 hours ago, pixelsearch said:

I maybe mistaken, but how could ever the following test be True in Func myResult() when _ImageSearch() and _ImageSearchArea() Returns are only 0 or 1 ?

You are right.

Local $Variable

; Func _ImageSearch() : Return Value(s): Success=1 , Failure=0
; --> simulates the possible results of : _ImageSearch(...) Or _ImageSearch(...)
$Variable = (0 Or 0)
ConsoleWrite(' 0 Or 0 : $Variable = ' & $Variable & @CRLF)
$Variable = (1 Or 0)
ConsoleWrite(' 1 Or 0 : $Variable = ' & $Variable & @CRLF)
$Variable = (0 Or 1)
ConsoleWrite(' 0 Or 1 : $Variable = ' & $Variable & @CRLF)
$Variable = (1 Or 1)
ConsoleWrite(' 1 Or 1 : $Variable = ' & $Variable & @CRLF)

; ==> $Variable is either True or False
$Variable = True
ConsoleWrite('! IsArray = ' & IsArray($Variable) & @CRLF)
$Variable = False
ConsoleWrite('! IsArray = ' & IsArray($Variable) & @CRLF)

Summary : If IsArray($Variable) = True will never come true !


Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

@Musashi: thanks for the confirmation.

@Polistotele: after googling on the sentence "If IsArray($Variable) = True", I wonder where you found this erroneous syntax in your script because you apply it to _ImageSearch() which will never return an Array. I didn't find your syntax in any post related to _ImageSearch()

$Variable = _ImageSearch(...) Or _ImageSearch(...)
If IsArray($Variable) = True Then ; this will never happen
    ...
Else
    $Variable = _ImageSearch(...) Or _ImageSearch(...)
    If IsArray($Variable) = True Then ; impossible too
        ...
    EndIf
EndIf

When BrewmanNH used this kind of nesting in Dec 2011, he applied it to $Variable = PixelSearch(...) as we can see here and it was correct because PixelSearch(...) returns an Array when successful. This is BrewmanNH's code :

$Variable = PixelSearch(...)
If IsArray($Variable) = True Then ; correct
    ...
Else
    $Variable = PixelSearch(...)
    If IsArray($Variable) = True Then ; correct
        ...
    EndIf
EndIf

Maybe one did copy his script, thinking he could apply it to _ImageSearch() without any other change... wrong try !
To solve this 1st issue, you should do what all other posters did in their scripts, testing only one image per line, then testing if the Return is 1 (success) :

$Variable = _ImageSearch(...)
If $Variable = 1 Then

Here are a few interesting links I found in AutoIt concerning _ImageSearch()

LINK1 : 8 pages of comments, OP is Centrally (thread created in 2013) . The whole pages should be read when you got an issue to see how other posters solved it (or at least tried to) . You would have immediately noticed how Centrally scripted, in his 1st post :

global $y = 0, $x = 0 ; always good to write Global (especially on $x & $y)

Func checkForImage()
Local $search = _ImageSearch(...)
If $search = 1 Then

LINK2 : tbodine88's code shows exactly what Nine asked you to do in his upper post (testing all DllCall possible error values) as it may help solve your #2 issue

LINK3 : JohnOne's about  #include <ImageSearch.au3> vs #include "ImageSearch.au3"

LINK4 : guestscripter's (2015) whole package "ImageSearch2015.zip" which seems to solve a lot of issues.
And for all other posters whining later in the same thread that his additional link "ImageSearch15.au3" wasn't working anymore (a version of ImageSearch Library without the built-in Example and Debugging) ... he pasted that additional script "ImageSearch15.au3" at the very end of his post, the same day he wrote it !

LINK5 : guestscripter's again (2018) showing he didn't modify his precedent download package (good news !) : 10.659 downloads.

LINK6 : BrewmanNH's "That's probably one of the worst reasons for using ImageSearch I've seen yet."
Impossible not to smile (at least) when reading this sentence :D
I guess many posters who created an account to ask for help used the function for game automation, invoking disguised reasons... which will make JLogan3o13 react :

LINK7 : JLogan3o13's "I was curious how long this thread would go after being resurrected before someone ruined it for everyone."

LINK8 : kangkeng's original thread (2008) : 13 pages of comments

You may also google on "Miguel7" "AutoHotKey" "ImageSearch" which links to 10 ImageSearch Tips & Tricks (2014) that could help you.

Good luck with all these various dll's from 2008 / 2010 / 2012, let's hope they can be trusted  without any danger.

Edited by pixelsearch

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

×
×
  • Create New...