Jump to content

line 44 ImageSearch error when launching another script using ImageSearch


Go to solution Solved by markyrocks,

Recommended Posts

my 2nd script works fine when triggered on its own. but when i launch my 1st script which then triggers the 2nd script, i get a line 44 error. anyone know why that is?

 

here's my 1st script:

 

#include <ImageSearch.au3>

Run("C:\Program Files (x86)\AutoIt3\AutoIt3.exe " & chr(34) & "d:\my documents\bat\test2.au3" & chr(34))

 

here's my 2nd script:

#include <Array.au3>
#include <File.au3>
#include <Date.au3>
#include <Debug.au3>
#include <ImageSearch.au3>

Local $x, $y
Local $search = _ImageSearchArea('D:\My Documents\imagesearch\thinkorswim_7x4(1&5m).png', 1, 0, 0, 500, 400, $x, $y, 0)
    sleep(100)
    ;WinMove($hArray[$i][1], "",-3848,-8, 3856,2136)
    ;msgbox(0,"",$search)
    If $search = 1 Then
        ;msgbox(0,"","Moving to -3850,0,1936,1070")
        WinMove($hArray[$i][1], "",-3850,0,1936,1070)
        sleep(100)
        Local $pos=WinGetPos($hArray[$i][1])
        While $pos[0] <> -3850 Or $pos[1] <> 0 Or $pos[2] <> 1936 Or $pos[3] <> 1070
            WinMove($hArray[$i][1], "",-3850,0,1936,1070)
            sleep(100)
            $pos=WinGetPos($hArray[$i][1])
            ;msgbox(0,"",$pos)
            FileWriteLine($hFileOpen, "$pos: " & $pos)
        WEnd
        $cnt+=1
    Else
        ;msgbox(0,"","Moving to -1929,0,1936,1070")
        WinMove($hArray[$i][1], "",-1929,0,1936,1070)
        sleep(100)
        $pos=WinGetPos($hArray[$i][1])
        While $pos[0] <> -1929 Or $pos[1] <> 0 Or $pos[2] <> 1936 Or $pos[3] <> 1070
            WinMove($hArray[$i][1], "",-1929,0,1936,1070)
            sleep(100)
            $pos=WinGetPos($hArray[$i][1])
        WEnd
    EndIf

 

Link to comment
Share on other sites

I think I may have come across this issue b4 playing around with image search.  You can just go into the image search au3 and change that line from if $result[0] etc to something like

if IsArray($result) and $result[0]="0" then return 0

That way it won't try to access like an array unless it's sure that it is one.  

Link to comment
Share on other sites

  • Solution
1 hour ago, dwaynek said:

got another error after making that change...

AutoIt3_kkfRWuXV82.png

 

;change this

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

; to this

if not IsArray($result) or $result[0]="0" then return 0

 

I had a feeling something like that would happen. That should fix it.  

Edited by markyrocks
Link to comment
Share on other sites

2 hours ago, Professor_Bernd said:

I suspect he is using that source.

Here’s the thing, for ImageSearch.au3 that exact line 44 array subscript error has been encountered literally a dozen times, including in the thread you linked.

But I have used the same functions, e.g. _ImageSearchArea(), without problem.  But I am using _ImageSearch.au3 (with a leading underscore), which can be found here:

 

I think maybe it’s a newer version??

Anyway, the functions always return an array and if nothing is found then $result[0]=0, just like the error is expecting.

 

Code hard, but don’t hard code...

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