Sign in to follow this  
Followers 0
blessthefall

I know there has to be a simple solution...

25 posts in this topic

I'm not completely new to AutoIt, but I'm by no means a veteran. I've been wondering how to do this for months now; usually when I have problems with AutoIt I consult the help file or google. Thus far I've still been at a loss.

I'm trying to figure out how to end a loop when a certain condition (unrelated to the loop) changes.

This is essentially a dumbed down example of what I'm trying to do:

---------------------------------------------------------------------

$checksum = PixelChecksum(x1,y1, x2,y2)

While $checksum = PixelChecksum(x1,y1, x2,y2)

$abc = 0

Do

Send ("abcgefghijklmnopqrstuvwxyz")

$abc = $abc + 1

Until $abc = 100

WEnd

----------------------------------------------------------------------

*The coordinates aren't important.

What I want to do is halt the loop when the condition (my PixelChecksum) changes even if the loop hasn't fully completed.

Simply checking the PixelChecksum after each " Send ("abcgefghijklmnopqrstuvwxyz") " doesn't work for me because if the pixel area changes at "a" the loop won't be halted until after "z" has been sent. Also what I'm doing is much longer and complicated than that. I just want a way to halt it instantly.

Hope I explained this well enough =/

Share this post


Link to post
Share on other sites



I've checked the help file and find the ExitLoop command.

$checksum = PixelChecksum(x1,y1, x2,y2)

While $checksum = PixelChecksum(x1,y1, x2,y2)
  $abc = 0
  Do
    Send ("abcgefghijklmnopqrstuvwxyz")
    $abc = $abc + 1
  Until $abc = 100
  if $abc = 100 then ExitLoop
WEnd

It seems to be what you need :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

"a" through "z" are ascii values 97 through 122. So...

$checksum = PixelChecksum(x1,y1, x2,y2)

While $checksum = PixelChecksum(x1,y1, x2,y2)

$abc = 0
Do

for $i = 97 to 122
    send("{ASC " & $i & "}")
    $abc = $abc + 1
    if Not (PixelChecksum(x1,y1, x2,y2) = $checksum) then exitloop
next

Until $abc = 100
WEnd

or something similar. Does that help?

Edited by k3v

Share this post


Link to post
Share on other sites

I've checked the help file and find the ExitLoop command.

$checksum = PixelChecksum(x1,y1, x2,y2)

While $checksum = PixelChecksum(x1,y1, x2,y2)
  $abc = 0
  Do
    Send ("abcgefghijklmnopqrstuvwxyz")
    $abc = $abc + 1
  Until $abc = 100
  if $abc = 100 then ExitLoop
WEnd

It seems to be what you need :)

I think you may have misunderstood my problem. The way this is set up, the script will execute ' Send ("abc...") ' 100 times regardless of what happens in my PixelChecksum area. It isn't until after the Do loop is completed that the script goes back and checks the PixelChecksum area.

Share this post


Link to post
Share on other sites

"a" through "z" are ascii values 97 through 122. So...

$checksum = PixelChecksum(x1,y1, x2,y2)

While $checksum = PixelChecksum(x1,y1, x2,y2)

$abc = 0
Do

for $i = 97 to 122
    send("{ASC " & $i & "}")
    $abc = $abc + 1
    if Not (PixelChecksum(x1,y1, x2,y2) = $checksum) then exitloop
next

Until $abc = 100
WEnd

or something similar. Does that help?

Actually this is closer to what I was looking for, however I think the solution is very situational (it only applies to this particular script). What if instead of " Send ("abc...") " I was having it execute a long series of complicated commands. All I want to do is to stop whatever it's doing inside of the While <-> WEnd the instant something changes in my pixel field. It's irrelevant what I'm trying to make the script do, I want to focus more on what I'm trying to get it not to do.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

All I want to do is to stop whatever it's doing inside of the While <-> WEnd the instant something changes in my pixel field. It's irrelevant what I'm trying to make the script do, I want to focus more on what I'm trying to get it not to do.

I think the problem here is the repeat inside the while.

ExitLoop seems to be what you need

Terminate a While/Do/For loop.

but only works with While, Do and For loops.

Edit: If you can transform the repeat into a do-until that should work (if i understand it correctly).

Edited by gulthaw

Share this post


Link to post
Share on other sites

In that case, one would need more information about the long series of commands you plan to execute. Can you provide an example that more closely resembles your intentions?

Share this post


Link to post
Share on other sites

In that case, one would need more information about the long series of commands you plan to execute. Can you provide an example that more closely resembles your intentions?

I actually plan on using this for a number of different things. I'm experimenting with bots for games.

The best way I can describe what I want is to leave ' Send ("abcdefghijklmnopqrstuvqxyz") ' unchanged. Now let's say that something changed in my pixel field between "d" and "e" being sent. I want the script to have only sent "abcd" nothing else because something changed at that point. I'm looking for a universal way to do this, regardless of what's in While <-> WEnd.

Maybe it's not possible?

Share this post


Link to post
Share on other sites

Use case statements instead of a do - until in your loop.

I've tried a number of different things... nothing seemed to work for me. I'm not extremely experienced with AutoIt... That's why I came here =).

$checksum = PixelChecksum(x1,y1, x2,y2)

While $checksum = PixelChecksum(x1,y1, x2,y2)

$abc = 0

While $abc < 100

Send ("abcgefghijklmnopqrstuvwxyz")

$abc = $abc + 1

WEnd

WEnd

I suppose this is what you were suggesting, tho this doesn't fix my problem.

Share this post


Link to post
Share on other sites

As it stands, your Send() command is a single instruction that will be completed before any subsequent comparisons are made. That being said, I'm afraid I'm out of "conventional" ideas... (a thought I had briefly is WAY outside the box, and could do more to create more problems before resolving yours)

Share this post


Link to post
Share on other sites

no, what I had in mind is somehting like this:

while 1
    Select
        case $abc < 100
        ;do something
        case $abc > 100 
        ;do something
        case Else   
        ;do something
    EndSelect
WEnd

Share this post


Link to post
Share on other sites

As it stands, your Send() command is a single instruction that will be completed before any subsequent comparisons are made. That being said, I'm afraid I'm out of "conventional" ideas... (a thought I had briefly is WAY outside the box, and could do more to create more problems before resolving yours)

I figured that it might come down to that =(. As far as something unconventional, would it be possible to have two different scripts running in conjunction with each other? When one detects a change, I could have it halt the other script.

^^^ - Something like that viable?

Btw I really appreciate your help.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

as i see and understand you have to change checksum to exitloop

$checksum = PixelChecksum(x1,y1, x2,y2)

While $checksum = PixelChecksum(x1,y1, x2,y2)

$abc = 0

Do

Send ("abcgefghijklmnopqrstuvwxyz")

$abc = $abc + 1

Until $abc = 100

WEnd

while statement will continue cuz $checksum = PixelChecksum(x1,y1, x2,y2) still same.

you have to stop this command to exit loop.

or try to insert $checksum = "" after until, if i understand you correctly, it will work

Edited by mistakilla

:alien: ~ Every Living Thing is a Code Snippet of World Application ~ :alien:

Share this post


Link to post
Share on other sites

no, what I had in mind is somehting like this:

while 1
    Select
        case $abc < 100
    ;do something
        case $abc > 100 
    ;do something
        case Else   
    ;do something
    EndSelect
WEnd

Ah I'll have to read up on it a bit more, I'm not familiar with this as I've not used them before.

Might be my solution but at this point I'm really not sure.

Share this post


Link to post
Share on other sites

As far as something unconventional, would it be possible to have two different scripts running in conjunction with each other? When one detects a change, I could have it halt the other script.

Kind-of...

If your Send() command was an executable by itslef, the you could launch it instead of running Send() from your script... that way, your script would continue to process after launching it... when the desired contition occurs, do something like activate another window... (thing is, the Send() command will complete no matter what... but activating another window will prevent the remainder of the characters from being sent to their original destination.)

$checksum = PixelChecksum(x1,y1, x2,y2)

While $checksum = PixelChecksum(x1,y1, x2,y2)

$abc = 0
Do

    run("sendstuff.exe")
    $abc = $abc + 1
    if Not (PixelChecksum(x1,y1, x2,y2) = $checksum) then 
        winactivate("someotherwindow")
        exitloop
    endif

Until $abc = 100
WEnd

Possible timing issues here, and you may not wish to take priority away from your main window just to break the Send() process.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Woops... (ended up replying twice... sorry folks!)

Edited by k3v

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

(man... thought I was going crazy... maybe I am... )

just figured out there is more than one page... really sorry, people!

(can anyone tell me how to delete all these duplicates?)

Edited by k3v

Share this post


Link to post
Share on other sites

Kind-of...

If your Send() command was an executable by itslef, the you could launch it instead of running Send() from your script... that way, your script would continue to process after launching it... when the desired contition occurs, do something like activate another window... (thing is, the Send() command will complete no matter what... but activating another window will prevent the remainder of the characters from being sent to their original destination.)

$checksum = PixelChecksum(x1,y1, x2,y2)

While $checksum = PixelChecksum(x1,y1, x2,y2)

$abc = 0
Do

    run("sendstuff.exe")
    $abc = $abc + 1
    if Not (PixelChecksum(x1,y1, x2,y2) = $checksum) then 
        winactivate("someotherwindow")
        exitloop
    endif

Until $abc = 100
WEnd

Possible timing issues here, and you may not wish to take priority away from your main window just to break the Send() process.

But instead of opening "someotherwindow" could i just replace it with a command that closes "sendstuff.exe"?

Share this post


Link to post
Share on other sites

Sure... get the PID when you launch it, and kill the PID when the condition occurs...

But I've not researched this, so you may need to check the help file for doing all that. Or maybe someone here has some quick pointers...?

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