ImageSearch.au3 startet nicht - Error Meldung !

  • Hi, ich bin neu hier :)
    Ich hab ein Problem, nämlich habe ich mir zum Test einen Bot erstellt, der den Kalender aufm Desktop erkennen soll und dann mit der Maus hingehen soll:

    [autoit]

    #include <ImageSearch.au3>
    $x1=0
    $y1=0

    [/autoit][autoit][/autoit][autoit]

    $result= _ImageSearch('Kalender.PNG',1,$x1,$y1,100)

    [/autoit][autoit][/autoit][autoit]

    If $result=1 Then
    MouseMove($x1,$y1,100)
    Else
    MsgBox(1, 'Fehler', 'Nichts gefunden')
    EndIf

    [/autoit]


    Wenn ich ihn starte, kommt folgende Meldung:
    if $result[0]="0" then return 0
    if $result^ ERROR

    Bitte helft mir, ich möchte das mit ImageSearch ma hingkriegen :(

    Edit BugFix: Also mit 'Bot' hast du dich sehr unglücklich ausgedrückt (habs auch aus deinem Titel gestrichen). Dadrunter verstehen wir in unseren Forenregeln verbotene Skripte für unerlaubte Vorteilsnahme.

    Edit: Ok, wie nennt man das dann ? ^^ Ach ja, unterm Error steht dann noch : Subsrcipt used with non-Arry variable.

    2 Mal editiert, zuletzt von schaccels (13. Juni 2011 um 08:53)

  • Kurze Antwort: Die Funktion liefert kein Array zurück, also findet vermutlich nichts.

    Warum das so ist und ob es Rückgabewerte / Errorcodes für Fehlerfälle wie diesen gibt die man abfragen kann kann ich dir nicht beantworten, weil die imagesearch.au3 nicht zu den Standardfunktionen von Autoit gehört und ich auch keinen Downloadlink dazu finden kann (bzw. ohne acc dort nichts herunterladen darf). Da das ganze aber scheinbar aus dem autoit Bot forum stammt frag am besten dort nach oder wirf selbst einen Blick in die imagesearch.au3 um herauszufinden welche Rückgabewerte diese Funktion liefert.

    Alternativ kannst du auch diese imagesearch.au3 hier als Anhang oder in Quellcode Form posten. (sofern der Autor dies nicht untersagt hat...)

  • @ misterspeed:
    Nein, es ist nicht aus dem Forum, sondern von einem YouTube-Video, wo eigentlich alles gleichgemacht wurde, trotzdem funktioniert meins nicht. Meinst du das hier als Alternative ? :

    Spoiler anzeigen
    [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; 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)
    return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    ; 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

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; 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)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
    sleep(100)
    $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance)
    if $result > 0 Then
    return 1
    EndIf
    WEnd
    return 0
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; 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)
    $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)
    if $result > 0 Then
    return $i
    EndIf
    Next
    WEnd
    return 0
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    @ Towdollarbrille:
    Wurde im Video nicht gemacht, wenn ich es machen, kommt wieder der gleiche Error. Der Dateipfad ist wohl nicht zwingend notwendig.

  • Naja da hat wohl jemand geschlampt. In der Funktion _imagesearchArea wird nicht geprüft ob die Variable $result überhaupt ein Array ist (Zeile 40). Wenn der DLL Call scheitert, weil du dein Script zum Beispiel in 64bit ausführst und die DLL nur für 32bit gedacht ist kann sowas zum Beispiel passieren. Eine mögliche Lösung wäre es in der Funktion ein isArray() einzubauen oder aber sicherzustellen, dass du die korrekte dll verwendest, bzw. dein Script entsprechend in 32bit oder 64bit ausführst.

    EDIT:

    Den Sinn darin die X und Y Werte innerhalb der Funktion zu ändern verstehe ich auch nicht, denn diese Werte werden ja nichtmal an die aufrufende Funktion zurückgegeben oder für irgendwas innerhalb der Funktion benutzt. Das nutzt also nur was wenn man die beiden Variablen global definiert hat. Ausbaufähig das ganze, aber naja einen sinnvollen Einsatzzweck sehe ich sowieso nicht in dieser Image und Pixel Sucherei.

    2 Mal editiert, zuletzt von misterspeed (13. Juni 2011 um 18:04)