Jump to content

Debug Help? Please Read Through


 Share

Recommended Posts

I wrote the following script to automate a task, and for whatever reason it doesnt seem to work correctly, i was just posting it to see if anybody could see anything offhand that would cause this to happen.

; Resolution 1280x1024
HotKeySet("{#p}", "Terminate")
Sleep(20000);
$skar = 2
Sleep(20000);
AutoItSetOption("PixelCoordMode",0)


While $skar > 1 
    If PixelSearch( 897, 746, 912, 751, 4860718 ) Then 
  Sleep(20000);
  Send("!i");
  Sleep(2000);
  Send("{ENTER}");
  Sleep(2000);
  Send("{ENTER}");
  Sleep(2000);
  $sc = PixelSearch ( 202, 53, 222, 233, 1201585 );
    EndIf
    If Not @error Then
  step2();
    EndIf
    If @error Then
  search();
    EndIf
Wend


Func step2()
MouseMove($sc[0], $sc[1]); grabs coordinates that the PixelSearch found
sleep(1000); 
MouseClick("left");
Sleep(1555);
Send("{ENTER}");
Sleep(1555);
MouseMove(64, 252);
Sleep(1500);
MouseClick("left");
Sleep(1000);
MouseClick("left");
Sleep(1000);
MouseClick("left");
Sleep(500);
Send("{ENTER}");
Sleep(1000);
MouseMove(176, 82);
Sleep(1000);
MouseClick("left");
Sleep(21000);
AutoItSetOption("MouseCoordMode", 0)
Sleep(3000);
AutoItSetOption("SendKeyDelay", 0235);
Send ("!i");
Sleep(0250);
Send ("{NUMPADADD}");
Sleep (0250);
Send ("{ENTER}");
sleep(0250);
MouseMove(1203,120,10);
sleep(0250);
Send ("{ENTER}");
sleep(0250);
Send ("{ESCAPE}");
sleep(0250);
Send ("{ESCAPE}");
Sleep (0250);
EndFunc

Func search()
Sleep(1000);
MouseMove(378,237);
Sleep(1000);
MouseClick("left");
EndFunc

Func terminate()
Exit
EndFunc

When i say "work" i dont mean run...it does run, there aren't any syntax errors it reports.

But, it gets stuck in an infinite loop of essentially executing the search() function over and over again, even though i know for a fact the pixel i am looking for is within the defined set of coordinates.

If anybody can see anything offhand of why this wouldn't work...any help would be much appreciated.

Link to comment
Share on other sites

HotKeySet("{#p}", "Terminate")

Should be HotKeySet("#p", "Terminate")

:whistle: but I guess that doesn't solve your problem

Maybe try explicitly declaring Global/Local (as appropriate) variables. See the keyword "Dim" in the help file.

Also use AutoItSetOption("TrayIconDebug",1) if you have the AutoIt tray icon showing. Mouse over to reveal the current line being executed.

BTW, $skar is never decremented so While $skar > 1 will always be true.

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Also .. I don't think the @error in these two lines are necessarily looking at the same value ..

:
:
If Not @error Then
 step2();
EndIf
If @error Then
 search();
EndIf
:
:

Cos if step2() executes, @error will reflect the happenings there by the time it gets to the second check above. :whistle:

HTH

Link to comment
Share on other sites

Maybe try explicitly declaring Global/Local (as appropriate) variables. See the keyword "Dim" in the help file.

BTW, $skar is never decremented so While $skar > 1 will always be true.

-- I basically used the variable $skar just to create a simple loop so the script would run on itself over and over.

Also use AutoItSetOption("TrayIconDebug",1) if you have the AutoIt tray icon showing. Mouse over to reveal the current line being executed.

This is definitely REALLY helpful for testing, thank you for pointing this out!

I think what trids and Larry are saying will solve the problem, i had a feeling it was something along those lines. If it isn't that, its that the Pixels just can't be picked up by AutoIt in the application i'm using.

Thanks for all the helpful responses!

:whistle:

Link to comment
Share on other sites

What happens if the first PixelSearch succeeds immediately? It returns an array, which seems to skip the if clause, @error is not set so it enters function step2 which tries to use $sc - which hasn't been set up?

Even if this is not an error, if it ever succeeds then step2 will use the $sc data from the previous failed cycle

I also think that using PixelSearch directly in an if statement is dubious. I cannot find anywhere that defines what the an array resolves to when used as an expression. Currently with AutoIt3 seems to treat it as false, but since it isn't defined then it could possibly change in the future. I would remove the PixelSearchout of the if statement and check @error directly

Just my 2c worth

GrahamS

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