Jump to content

Error: "Subscript used with non-Array Variable" after compiling script.


kukkuk
 Share

Recommended Posts

This script works just fine as .au3 file. After compiling it to an .exe it gets error: "Subscript used with non-Array Variable". I really dont get the difference - why is it working in .au3 and not in. exe.

Part of my code where it gets the error:

$slot1x = 538
       $slot1y = 367
       $offset = 27
      $x = 0
      $y = 0

      For $i = 0 To 9
         For $j = 0 To 5
                  MouseMove($slot1x + ($i * $offset), $slot1y + ($j * $offset),3)        
            
            $pos = MouseGetPos()
            $res = _ImageSearchArea('req.png', 1, $pos[0]-150, $pos[1], $pos[0], 638, $x, $y, 100)
            If $res = 0 Then           
                  PixelSearch($pos[0]-250,200,$pos[0]-100,$pos[1]+50,12564995,3)
                  If @error Then
                        Sleep(Random(50,100))
                        MouseClick("right")
                  Endif
            Else
            Sleep(Random(50,100))
            MouseClick("right")
            Endif
         Next
      Next

After clicking the first position (538,367) and doing image search there is an error which I described above.

After removing the:

$res = _ImageSearchArea('req.png', 1, $pos[0]-150, $pos[1], $pos[0], 638, $x, $y, 100)
            If $res = 0 Then
         Endif

It works fine.

_ImageSearchArea is a function from ImageSearch which is included.

Code:

Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)
    $findImage = "*TRANSBLACK " & $findImage
    if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
    if $result = "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],"|")
   If(UBound($array) >= 4) Then
      $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
   EndIf
EndFunc
Link to comment
Share on other sites

Welcome to AutoIt and the forum!

This is no 24-hours-support-forum. So please wait at least 24 hours before you bumpt a thread.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I would start with that function call ($pos = MouseGetPos())

and see if you are actually getting an array back - check for error value and if no error continue?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

You are using a relative path to the PNG file. You should determine a way to determine exactly where the PNG file is and use that. The reason you get the error is likely because your EXE can't find the PNG file, but since you aren't using any error checking, it processes the function anyways... which probably is returning a NULL or 0 value, rather than an array value, thus causing the error.

Link to comment
Share on other sites

I have tried such a code:

$slot1x = 538
      $slot1y = 367
      $offset = 27
      $x = 0
      $y = 0

      DEBUG("Stashing in tab2")

Sleep(1500)

      For $i = 0 To 9
         For $j = 0 To 5
                  MouseMove($slot1x + ($i * $offset), $slot1y + ($j * $offset),3)        
            
            $pos = MouseGetPos()
         if isarray($pos) then
            Debug("It is an array!")
         endif
         Sleep (1000)
        
         Debug("Mouse pos: x:" & $pos[0] & " y:" & $pos[1] & "")
        
         Sleep (3000)
            
            $res = _ImageSearchArea('req.png', 1, $pos[0]-150, $pos[1], $pos[0], 638, $x, $y, 100);
            If $res = 0 Then
            Debug("Mouse pos: x:" & $pos[0] & " y:" & $pos[1] & "")               
            Else
            Debug("Found it")
            Endif
         Next
      Next

I get the result that $pos is an array and can see the $pos[0] and $pos[1] results. So there is no error and I am always getting an array back. And after compiling it to an exe I still have the same error... "Subscript used with non-Array Variable".

I have also tried to change:

$res = _ImageSearchArea('req.png', 1, $pos[0]-150, $pos[1], $pos[0], 638, $x, $y, 100);

to

$res = _ImageSearchArea('D:\Users\Mateusz_2\Desktop\req.png', 1, $pos[0]-150, $pos[1], $pos[0], 638, $x, $y, 100);

It is the full path of that file. Still I have the same error after compiling.

I will be thankfull for any further help!

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