Jump to content
Sign in to follow this  
ends

Error: Subscript used with non-Array variable

Recommended Posts

ends

Hello I'm new to AutoIt. I've been messing around with it for awhile now and have made several scripts that have been very useful to me. But i can't seem to get this one to work. I want it to find a button that appears in differant areas on the screen and click it. With this one it's giving me an error of Subscript used with non-Array variable. Which i have no idea what that means. :) I've done many searches on the forums and can't find anything that helps me or maybe i have found something but don't understand it.

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

Sleep(15000);
$i=0;


Do

destroy()
Until $i=1000000;


Func destroy()
Send("{i}");
sleep(2000);
MouseMove(648,660, 2);
Sleep(500);
MouseClick("right", 648, 660, 1);
Sleep(1000);
$coord = PixelSearch( 655, 738, 631, 729, 14281964);
MouseMove($coord[0],$coord[1]);
sleep(500);
MouseClick("left",$coord[0],$coord[1]);
sleep(1000)
Send("{i}");
sleep(2000)

EndFunc


Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

please help....

Share this post


Link to post
Share on other sites
tAKTelapis

Well, try this

didnt modify much

i changed your Do loop into a For loop (nothing wrong with how it was, but i think for looks nicer :))

and most importantly, added an error check onto your pixel search.. near as i can tell, the reason that $coord[0] and $coord[1] were showing as errors is because the pixel search was failing.

otherwise it should work (i have NO idea what you are pixel searching for, but my computer does not have it on the desktop.)

Global $Paused ; added paused as a global as it reigstered as being used without being delcared
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

Sleep(15000);

For $i = 1 to 1000000 step 1
destroy()
Next

Func destroy()
    Send("{i}");
    sleep(2000);
    MouseMove(648,660, 2);
    Sleep(500);
    MouseClick("right", 648, 660, 1);
    Sleep(1000);
    $coord = PixelSearch( 655, 738, 631, 729, 14281964);
    ;added error check
        if @error = 1 Then
            MsgBox(0, "test", "Pixel search failed")
            Exit
        EndIf ; end of error check
    MouseMove($coord[0],$coord[1]);
    sleep(500);
    MouseClick("left",$coord[0],$coord[1]);
    sleep(1000)
    Send("{i}");
    sleep(2000)
EndFunc


Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit
EndFunc
Edited by tAKTelapis

Share this post


Link to post
Share on other sites
xcal

You could also pause that $coord part of your script until it's an array, like...

While 1

$coord = PixelSearch( 655, 738, 631, 729, 14281964)

If IsArray($coord) Then ExitLoop

Sleep(100)

Wend

edit -

Looks like your pause doesn't do anything?

Might want to change your loop to something like...

Do

If Not $Paused Then destroy()

Until $i=1000000;

Edited by xcal

Share this post


Link to post
Share on other sites
tAKTelapis

Yeah, it appears to me that his Pause is out of whack.

I never studied that, i was looking more at the array issue.

Share this post


Link to post
Share on other sites
ends

Thank you very much for your help. It seems the pixel search failed. I'm using this inside a game to delete an in game item. Right click to use radial menu on the item then find the destroy option to delete it. Why would the pixel search fail? could it be cause there are other matches or no matches at all? And yea i really don't use the pause at all cause it doesn't seem to work.

Share this post


Link to post
Share on other sites
ends

ok i think i got it... guess i too didn't understand the cords for Pixelsearch until i read the post "Question for Pixelsearch, Coordinates". It's selecting the wrong button but i think if i mess around with it i bit i should be able to get it. Thank you all for your help. :)

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  

×