Sign in to follow this  
Followers 0
aggixx

Line -1: Error: Subscript used with non-variable array

5 posts in this topic

So, I seem to have encountered this problem before, but I don't remember how I fixed it.

I have written a program that works just fine on my computer, but when I give it to my friends, it does not work for them (probably something to do with the AutoIt installation...).

I have thoroughly looked through my program, and every single time that subscript has been used, there is an IsArray() right before it.

Any ideas how to manage this?

Share this post


Link to post
Share on other sites



post part of script it errors at

Share this post


Link to post
Share on other sites

post part of script it errors at

Line -1? So I guess that includes the whole script?

;Dark Orbit: Bonus Box Bot v2
;Revision 0
;
;by aggixx

;--------------------

;START PRE
$log = FileOpen( @scriptdir & "\DOBBlog.txt", 1 )
;$time = StringSplit( _Date_Time_GetLocalTime(), ";", 1 )
LogEvent(@CRLF & "--- Program Initiated ---")
;LogEvent(@CRLF & "--- Program Initiated -- " & $time[1] & "/" & $time[2] & "/" & $time[4] & " ---")

;Include
#include <ImageSearch.au3>
;#include <Date.au3>

;FileInstall
FileInstall("C:\Users\aggixx\Desktop\AU3 Scripts\DOcorner.jpeg", @TempDir & "\DOcorner.jpeg")

;Constants
$hwnd = WinGetHandle("www.DarkOrbit.com - Mozilla Firefox", "")
$title = "www.DarkOrbit.com - Mozilla Firefox"
$xos = 0
$yos = -5

;Variables
$calibrated = false
$mappos = ""
$mappos2 = ""
$movetimer = 0

;Settings
$searcharea = 0.5;Max distance to venture from base (out of 1)

;END PRE

WinMove( $title, "", 0, 0, default, default, 1 )
WinActivate( $title, "" )
$winstatus = Calibrate()

;--------------------

;START FUNCS

HotKeySet("{ESC}", "abort")
Func Abort()
    WinActivate( $title )
    If PixelChecksum( 76+$xos, 64+$yos, 116+$xos, 90+$yos, 3 ) <> 1238258892 Then Send("h")
    LogEvent( "Program closed..." & @CRLF )
    Exit
EndFunc

Func LogEvent($line)
;$time = StringSplit( _Date_Time_GetLocalTime(), ";", 1 )
;$line = "[" & $time[5] & ":" & $time[6] & ":" & $time[7] & "] " & $line
    Return FileWriteLine( $log, $line )
EndFunc

Func Calibrate()
    $xos = ""
    $yos = ""
    _ImageSearch(@TempDir & "\DOcorner.jpeg", 0, $xos, $yos, 20)
    Send("h")
    If $xos = "" Then
        Sleep(500)
        _ImageSearch(@TempDir & "\DOcorner.jpeg", 0, $xos, $yos, 20)
    EndIf
    If $xos = "" Then
        $xos = 8
        $yos = 60
        LogEvent( "!!! OFFSET NOT FOUND !!!" )
    Else
        $xos = $xos - 8
        $yos = $yos - 60
    EndIf
    If $calibrated = false Then
        $calibrated = true
        ConsoleWrite("X Alignment: " & $xos & @CRLF)
        ConsoleWrite("Y Alignment: " & $yos & @CRLF)
    EndIf
    LogEvent( "Calibrated to " & $xos & ", " & $yos & "." )
    Return WinGetPos( $title )
EndFunc

Func PKsearch()
    $danger = PixelGetColor( 820+$xos, 706+$yos )
    $ret = -1
    Switch $danger
    Case 14807295
        $ret = 0
    Case 16772505
        $ret = 1
    Case 16767296
        $ret = 2
    Case 263172
        $ret = -2
    Case 16751360
        $ret = 4
    Case 16751360
        $ret = 5
    EndSwitch
;SplashImageOn( "", "DO_" & $ret & ".bmp", 819+$xos, 21+$yos, 8+$xos, 713+$yos, 1 )
    Return $ret
EndFunc

Func Move($x = 0, $y = 0)
    MouseClick( "Left", 662 + $x + $xos, 603 + $y + $yos, 1, 1 )
EndFunc

Func MoveWait($x = 0, $y = 0)
    MouseClick( "Left", 662 + $x + $xos, 603 + $y + $yos, 1, 1 )
    While 1
        $oldmappos2 = $mappos2
        $mappos2 = PixelSearch( 662+$xos, 608+$yos, 811+$xos, 707+$yos, 0x37AA00, default, 2 )
        If IsArray( $mappos2 ) and IsArray( $oldmappos2 ) Then
            If $mappos2[0] = $oldmappos2[0] and $mappos2[1] = $oldmappos2[1] Then
                If $movetimer2 = 0 Then
                    $movetimer2 = TimerInit()
                EndIf
                If TimerDiff( $movetimer2 ) > 3000 Then
                    $movetimer2 = 0
                    LogEvent( "Destination reached... restarting main loop..." )
                    ExitLoop
                EndIf
            Else
                $movetimer2 = 0
            EndIf
        EndIf
    WEnd
EndFunc

Func MoveLoot($x = 0, $y = 0)
    LogEvent( "Moving to designated point..." )
    Move( $x, $y )
    LogEvent( "Success..." )
    
    While 1
    ;Start Loot
        
        SetError(0)
        
        $loot_search = PixelSearch( 0+$xos, 60+$yos, 819+$xos, 592+$yos, 0xFFC07A, 5, default )
        If IsArray($loot_search) Then
            LogEvent( "Found Bonus Box!!! ("&$loot_search[0]&","&$loot_search[1] & ")" )
            MouseClick( "Left", $loot_search[0]+5+$xos, $loot_search[1]+5+$yos, 1, 1 )
            Sleep(1500)
            Move( $x, $y )
        EndIf
        
        $loot_search = PixelSearch( 0, 592, 648, 648, 0xFFC07A, 5, default )
        If IsArray($loot_search) Then
            LogEvent( "Found Bonus Box!!! ("&$loot_search[0]&","&$loot_search[1] & ")" )
            MouseClick( "Left", $loot_search[0]+5+$xos, $loot_search[1]+5+$yos, 1, 1 )
            Sleep(1500)
            Move( $x, $y )
        EndIf
        
    ;End Loot
        
        If Not $winstatus = WinGetPos( $title ) Then
            LogEvent( "Window changes found... Calibrating..." )
            Calibrate()
        EndIf
        If WinActive( $title ) <> 1 Then
            LogEvent( "Window deactivated, reactivating..." )
            $ret = WinActivate( $title )
            If $ret = 1 Then
                LogEvent( "Success..." )
            Else
                LogEvent( "Failure..." )
            EndIf
        EndIf
    ;PK
        If PKsearch() > 0 Then
            LogEvent( "PKer Detected! Retreating..." )
            Move( 10, 10 )
            LogEvent( "Success... Waiting for PKer to leave area..." )
            Do
                Sleep(500)
            Until PKsearch() = 0
            LogEvent( "PKer has left, confirming..." )
            Sleep(100)
            Do
                Sleep(500)
            Until PKsearch() = 0
            LogEvent( "Confirmed..." )
        EndIf
    ;
        If PixelChecksum( 76+$xos, 64+$yos, 116+$xos, 90+$yos, 3 ) = 1238258892 Then Send("h")
    ;Check for done movement
        $oldmappos = $mappos
        $mappos = PixelSearch( 662+$xos, 608+$yos, 811+$xos, 707+$yos, 0x37AA00, default, 2 )
        If IsArray( $mappos ) and IsArray( $oldmappos ) Then
            If $mappos[0] = $oldmappos[0] and $mappos[1] = $oldmappos[1] Then
                If $movetimer = 0 Then
                    $movetimer = TimerInit()
                EndIf
                If TimerDiff( $movetimer ) > 3000 Then
                    $movetimer = 0
                    LogEvent( "Destination reached... restarting main loop..." )
                    ExitLoop
                EndIf
            Else
                $movetimer = 0
            EndIf
        EndIf
    WEnd
EndFunc

;END FUNCS

;--------------------

;Bring GP win to front, upper right
WinMove( $title, "", 0, 0, default, default, 1 )
WinActivate( $title, "" )

Sleep(100)

$winstatus = Calibrate()

Send("h")

;Main Loop
While 1
    LogEvent( "Picking a random destination..." )
    While 1
        $x = Random( 0.01, 149 )
        $y = Random( 0.01, 99 )
        If Sqrt( ($x * $x) + ($y * $y) ) < $searcharea * 180.277 Then
            ExitLoop
        EndIf
    WEnd
    LogEvent( "Success..." )
    MoveLoot($x, $y)
WEnd

Share this post


Link to post
Share on other sites

Hi.

Line -1: Compiled scripts return this "Line Number", as they don't have line numbers. Run the AU3 Stript from SciTE Editor to see line numbers.

You address an Array incorretly. Arrays start with [0] ([0][0] etc. for multi-dim-Arrays), use ubound($MyArray) to check the "size" of an array.

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Hi.

Line -1: Compiled scripts return this "Line Number", as they don't have line numbers. Run the AU3 Stript from SciTE Editor to see line numbers.

You address an Array incorretly. Arrays start with [0] ([0][0] etc. for multi-dim-Arrays), use ubound($MyArray) to check the "size" of an array.

Regards, Rudi.

Thanks for the clarification. I found the problem. It turns out I ended up making a very dumb error inside if the ImageSearch.au3.

FileInstall( "C:\Users\aggixx\Desktop\AU3 Scripts\ImageSearchDLL.dll", @ScriptDir & "ImageSearchDLL.dll" )

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
Sign in to follow this  
Followers 0