Jump to content

ImageSearch won't work


 Share

Recommended Posts

Hello everyone, i'm not so expert in autoit, but in these day, I spent some hours to create a script with imagesearch.. I have no syntax error and no logical error (cause the script has worked for some hours..).

So i tried to upgrade it and add another function, and there, the script started to give me:

if $result[0]="0" then return 0
if $result^ ERROR

So i surfed in the threads and i found the fix for it.

ANYWAY, the error was just for the last function, the other one was working fine.. just the last one (tested in a new file) gives that error, even if they're using the same library (ImageSearch.au3)

If i try to test the last one in the main project, no error but just don't work that function..

In that moment i fixed the $result error with:

If (IsArray($result) = False) Then Return 0

But now, all the functions are not working.. i tried adding a msgbox to see if the image was found or not, but it always says not found..

What could be the problem?
Anyway thanks for the helping and sorry for my bad english

Link to comment
Share on other sites

5 hours ago, Earthshine said:

Show all code for help. What you have showed us is nothing and all we can do is guess

Of course

#include <ImageSearch.au3>
#include <GDIPlus.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>

HotKeySet ("p", "quitme")

While 1

    $fileA = "C:\Users\fabry\Desktop\ImmaginiScript\Ricerca.png"


    _GDIPlus_Startup()

    $hImageA =_GDIPlus_ImageLoadFromFile($fileA) ;this is the file to search
    $hBitmapA = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageA)

    $x = 0
    $y = 0

    sleep(150)
    $result = _ImageSearch($hBitmapA, 1, $x, $y, 50, 0) ;Zero will search against your active screen
        If $result > 0 Then

        ;~ dostuff
    
        endif

    $fileB = "C:\Users\fabry\Desktop\ImmaginiScript\Inizio.png"


    _GDIPlus_Startup()

    $hImageB =_GDIPlus_ImageLoadFromFile($fileB) ;this is the file to search
    $hBitmapB = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageB)

    $x = 0
    $y = 0

    ;~  sleep(100)

    $result = _ImageSearch($hBitmapB, 1, $x, $y, 100, 0) ;Zero will search against your active screen
        If $result > 0 Then
        ;~  dostuff
    
        EndIf
    $fileC = "C:\Users\fabry\Desktop\ImmaginiScript\Preparazione.png"


    _GDIPlus_Startup()

    $hImageC =_GDIPlus_ImageLoadFromFile($fileC) ;this is the file to search
    $hBitmapC = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageC)

    $x = 0
    $y = 0
    sleep(300)
    $result = _ImageSearch($hBitmapC, 1, $x, $y, 50, 0) ;Zero will search against your active screen
        If $result > 0 Then
        ;~  dostuff
        endif
    $fileD = "C:\Users\fabry\Desktop\ImmaginiScript\SetPreimpostati.png"

    _GDIPlus_Startup()

    $hImageD =_GDIPlus_ImageLoadFromFile($fileD) ;this is the file to search
    $hBitmapD = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageD)

    $x = 0
    $y = 0
    sleep(550)
    $result = _ImageSearchArea($hBitmapD, 1, 1220, 875, 1440, 984, $x, $y, 70, 0) ;Zero will search against your active screen
        If $result > 0 Then
        ;~  dostuff
        EndIf
    $fileE = "C:\Users\fabry\Desktop\ImmaginiScript\Set1.png"

    _GDIPlus_Startup()

    $hImageE =_GDIPlus_ImageLoadFromFile($fileE) ;this is the file to search
    $hBitmapE = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageE)

    $x = 0
    $y = 0
    sleep(200)
    $result = _ImageSearch($hBitmapE, 1, $x, $y, 10, 0) ;Zero will search against your active screen
        If $result > 0 Then
        ;~  dostuff
        $fileCurv = "C:\Users\fabry\Desktop\ImmaginiScript\Curvatura.png"

        _GDIPlus_Startup()

        $hImageCurv =_GDIPlus_ImageLoadFromFile($fileCurv) ;this is the file to search
        $hBitmapCurv = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageCurv)

        $x = 0
        $y = 0

        $result = _ImageSearchArea($hBitmapCurv, 1, 824, 463, 1781, 953, $x, $y, 50, 0) ;Zero will search against your active screen
            If $result > 0 Then
            call ("Curvatura")
        ;~  Sleep (100)
            EndIf

        Call ("Distrutto")
        
    else

    $fileF = "C:\Users\fabry\Desktop\ImmaginiScript\Set2.png"

    _GDIPlus_Startup()

    $hImageF =_GDIPlus_ImageLoadFromFile($fileF) ;this is the file to search
    $hBitmapF = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageF)

    $x = 0
    $y = 0
    sleep(200)
    $result = _ImageSearch($hBitmapF, 1, $x, $y, 20, 0) ;Zero will search against your active screen
    If $result > 0 Then
    
    ;~  dostuff
    
    $fileCurv = "C:\Users\fabry\Desktop\ImmaginiScript\Fuoco.png"

    _GDIPlus_Startup()

    $hImageCurv =_GDIPlus_ImageLoadFromFile($fileCurv) ;this is the file to search
    $hBitmapCurv = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageCurv)

    $x = 0
    $y = 0

    $result = _ImageSearchArea($hBitmapCurv, 1, 824, 463, 1781, 953, $x, $y, 50, 0) ;Zero will search against your active screen
        If $result > 0 Then
        call ("Curvatura")
    ;~  Sleep (100)
        EndIf

        sleep(100)
        ;~ call("Distrutto")
    EndIf

    _GDIPlus_ImageDispose($hImageCurv)
    _GDIPlus_Shutdown()
    
    
    _GDIPlus_ImageDispose($hImageF)
    _GDIPlus_Shutdown()
    EndIf

    _GDIPlus_ImageDispose($hImageE)
    _GDIPlus_Shutdown()


    _GDIPlus_ImageDispose($hImageD)
    _GDIPlus_Shutdown()


    _GDIPlus_ImageDispose($hImageC)
    _GDIPlus_Shutdown()


    _GDIPlus_ImageDispose($hImageB)
    _GDIPlus_Shutdown()


    _GDIPlus_ImageDispose($hImageA)
    _GDIPlus_Shutdown()

WEnd


Func Curvatura()

    ;~  dostuff

EndFunc

Func Distrutto()

    $fileH = "C:\Users\fabry\Desktop\ImmaginiScript\Distrutto.png"


    _GDIPlus_Startup()

    $hImageH =_GDIPlus_ImageLoadFromFile($fileH) ;this is the file to search
    $hBitmapH = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageH)

    $x = 0
    $y = 0

    sleep(150)
    $result = _ImageSearch($hBitmapH, 1, $x, $y, 50, 0) ;Zero will search against your active screen
        If $result > 0 Then
        ;~ dostuff
        endif

    _GDIPlus_ImageDispose($hImageH)
    _GDIPlus_Shutdown()
endFunc

Func quitme()
    Exit
EndFunc

Some sleep/comment lines are written cause i was doing some tests..

Probably the code is not indented perfectly, i'm sorry for this..

I've slimmed down a little the code, by eliminating all the action inside the if, so it's easy to read i think.. anyway inside them there's just MouseMove, MouseClick, Sleep and Send commands

 

Anyway, the problems i said in the first message started with Func Distrutto().

Now, when i start the code in the SciTE the console says

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\fabry\Desktop\ImmaginiScript\Script.au3" /UserParams    
+>15:06:28 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0   Keyboard:00000410  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0410)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\fabry\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\fabry\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\fabry\Desktop\ImmaginiScript\Script.au3
+>15:06:28 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\fabry\Desktop\ImmaginiScript\Script.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
+>15:07:03 AutoIt3.exe ended.rc:0
+>15:07:03 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 35.08

And even is the code is running i can modify it.

(i stopped the code with Hotkey)

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

×
×
  • Create New...