Jump to content

While loop exit code?


smcombs
 Share

Recommended Posts

Ok I have a while loop that I need to find out which statement it has exited with. Or rather which statement became false. Here is my code:

While PixelGetColor(584,738,$kung) Or TimerDiff($timer) < 5000

;code that needs to be executed while top values are still true

Wend

How do I find out if PixelGetColor(584,738,$kung) made the loop exit out, Or TimerDiff($timer) < 5000 made the loop exit out.

Thanks for your help

Link to comment
Share on other sites

  • Moderators

Sure:

Global $f_pixel_exit = False
Global $f_timer_exit = False

While 1
    If Not PixelGetColor(584,738,$kung)Then
        $f_pixel_exit = True
        ExitLoop
    EndIf
    
    If TimerDiff($timer) >= 5000 Then
        $f_timer_exit = True
        ExitLoop
    EndIf
    Sleep(250)
WEnd

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Ok I have a while loop that I need to find out which statement it has exited with. Or rather which statement became false. Here is my code:

[/code]
While PixelGetColor(584,738,$kung) Or TimerDiff($timer) < 5000
     ;code that needs to be executed while top values are still true
Wend

How do I find out if PixelGetColor(584,738,$kung) made the loop exit out, Or TimerDiff($timer) < 5000 made the loop exit out.

Thanks for your help[/quote]

Either your script logic or your description is broken.  It can only exit the loop if the pixel is black (returns 0) [b]AND[/b] the timer is >= 5000.  Perhaps you meant:  [code]While PixelGetColor(584,738,$kung) And TimerDiff($timer) < 5000
    ;code that needs to be executed while top values are still true
Wend
If PixelGetColor(584, 738, $kung) Then
    ; Exited on TimerDiff() >= 5000
Else
    ; Exited on PixelGetColor() = 0 (black)
EndIf

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Ok I have a while loop that I need to find out which statement it has exited with. Or rather which statement became false. Here is my code:

While PixelGetColor(584,738,$kung) Or TimerDiff($timer) < 5000

;code that needs to be executed while top values are still true

Wend

How do I find out if PixelGetColor(584,738,$kung) made the loop exit out, Or TimerDiff($timer) < 5000 made the loop exit out.

Thanks for your help

$kung = GUICreate("My GUI")
GUISetState(@SW_SHOW)
Dim $pixelscolor = 0 , $begin = TimerInit() , $BOOL = True

While (PixelGetColor(100,100,$kung) <> $pixelscolor And  TimerDiff($begin) < 5000)

Wend
MsgBox(0,"", "PixelGetColor = " & _
PixelGetColor(100,100,$kung) & @CRLF & "pixelscolor = " & $pixelscolor & @CRLF _
& "TimerDiff = " & TimerDiff($begin) & @CRLF & "Timer = " & 5000 )

or

$kung = GUICreate("My GUI")
GUISetState(@SW_SHOW)
Dim $pixelscolor = 15791353 , $begin = TimerInit() , $BOOL = True

While (PixelGetColor(100,100,$kung) <> $pixelscolor And  TimerDiff($begin) < 5000)

Wend
MsgBox(0,"", "PixelGetColor = " & _
PixelGetColor(100,100,$kung) & @CRLF & "pixelscolor = " & $pixelscolor & @CRLF _
& "TimerDiff = " & TimerDiff($begin) & @CRLF & "Timer = " & 5000 )

Success: Returns decimal value of pixel's color.

Failure: Returns -1 if invalid coordinates.

or

if invalid coordinates.

$kung = GUICreate("My GUI")
GUISetState(@SW_SHOW)
Dim $pixelscolor = -1 ;if invalid coordinates
Dim $begin = TimerInit() 

While (PixelGetColor(100,100,$kung) <> $pixelscolor And  TimerDiff($begin) < 5000)

Wend
MsgBox(0,"", "PixelGetColor = " & _
PixelGetColor(100,100,$kung) & @CRLF & "pixelscolor = " & $pixelscolor & @CRLF _
& "TimerDiff = " & TimerDiff($begin) & @CRLF & "Timer = " & 5000 )
Edited by wolf9228

صرح السماء كان هنا

 

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