Jump to content

Recursion and Return


 Share

Recommended Posts

Func _DoOneSequence($iNumOfTimes = 1)
    Local $bIsSettingsButtonShowing
    For $eCC = 1 To $iNumOfTimes
        $bIsSettingsButtonShowing = _WaitForTheSettingsButtonToAppear()
        If $bIsSettingsButtonShowing = 1 Then
            _Main()
        EndIf
    Next
EndFunc   ;==>_DoOneSequence

Func _WaitForTheSettingsButtonToAppear()
    Local $iSettingsButtonFound
    _ShowScreen()
    Local $sColor = 0xDEF4FB
    $aColorFound = PixelSearch(200, 105, 228, 133, $sColor, 75)
    If IsArray($aColorFound) Then
        ConsoleWrite("Settings Button Found" & @CRLF)
        Return $iSettingsButtonFound = 1
    Else
        ConsoleWrite("Settings Button NOT Found" & @CRLF)
        Sleep(5555)
        _WaitForTheSettingsButtonToAppear()
    EndIf
EndFunc   ;==>_WaitForTheSettingsButtonToAppear

There's something I am not understanding about the recursive steps here.  If I keep the recursion here (after the "Else"), then $bIsSettingsButtonShowing = _WaitForTheSettingsButtonToAppear(), never equals 1.  Even though the Return sets it to 1.  If I remove the Else, then $bIsSettingsButtonShowing = _WaitForTheSettingsButtonToAppear() will set to 1.  Is there something I am doing wrong here?

 

Thanks for the help!

Link to comment
Share on other sites

The value of your Return statement is "$iSettingsButtonFound = 1", which is parsed as a condition, testing whether $iSettingsButtonFound has value 1 or not. Since it's clear that the condition is never met, it evaluates to False. So you return the boolean value False.

You want just "Return 1".

But I don't understand why you think recursion is needed here. I believe you just need a single loop, not two functions with one using recursion.

Which program do you automate? There may exist a cleaner way to achieve your goal.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Func _DoOneSequence($iNumOfTimes = 1)
    
    For $eCC = 1 To $iNumOfTimes
        If _WaitForTheSettingsButtonToAppear()=1 Then _Main()
    Next
    
EndFunc   ;==>_DoOneSequence

Func _WaitForTheSettingsButtonToAppear()

    _ShowScreen()
    Local $sColor = 0xDEF4FB
    $aColorFound = PixelSearch(200, 105, 228, 133, $sColor, 75)
    If IsArray($aColorFound) Then
        ConsoleWrite("Settings Button Found" & @CRLF)
        Return 1
    EndIf
    ConsoleWrite("Settings Button NOT Found" & @CRLF)
    Sleep(5555)
    Return _WaitForTheSettingsButtonToAppear()

EndFunc   ;==>_WaitForTheSettingsButtonToAppear

or

Func _DoOneSequence($iNumOfTimes = 1)
    
    For $eCC = 1 To $iNumOfTimes
        _WaitForTheSettingsButtonToAppear()
        _Main()
    Next
    
EndFunc   ;==>_DoOneSequence

Func _WaitForTheSettingsButtonToAppear()

    _ShowScreen()
    $aColorFound = PixelSearch(200, 105, 228, 133, 0xDEF4FB, 75)
    If IsArray($aColorFound) Then
        ConsoleWrite("Settings Button Found" & @CRLF)
        Return
    EndIf
    ConsoleWrite("Settings Button NOT Found" & @CRLF)
    Sleep(5555)
    _WaitForTheSettingsButtonToAppear()

EndFunc   ;==>_WaitForTheSettingsButtonToAppear

 

Edited by RTFC
Link to comment
Share on other sites

On 12/9/2017 at 1:56 AM, jchd said:

The value of your Return statement is "$iSettingsButtonFound = 1", which is parsed as a condition, testing whether $iSettingsButtonFound has value 1 or not. Since it's clear that the condition is never met, it evaluates to False. So you return the boolean value False.

You want just "Return 1".

But I don't understand why you think recursion is needed here. I believe you just need a single loop, not two functions with one using recursion.

Which program do you automate? There may exist a cleaner way to achieve your goal.

Wow, I feel really dumb.  I don't know why I didn't think of making this a loop.  And thanks for the info on the Return $iVariable = 1.  I changed it to this.  Lmk, if you see any spots for improvements.

 

Local $sColor = 0xDEF4FB
    While 1
        $aColorFound = PixelSearch(200, 105, 228, 133, $sColor, 75)
        If IsArray($aColorFound) Then
            ConsoleWrite("Settings Button Found" & @CRLF)
            Return 1
        EndIf
        Sleep(1111)
    WEnd

 

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