Jump to content
Sign in to follow this  
smcombs

While loop exit code?

Recommended Posts

smcombs

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

Share this post


Link to post
Share on other sites
SmOke_N

Create variables that tell you true or false?


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.

Share this post


Link to post
Share on other sites
smcombs

Can you give me an example of how i would do this?

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
wolf9228

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

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

 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.