Jump to content

Help with Logic


Recommended Posts

My code is not acting as I expected, and I know I must be doing something wrong (again)

Code is supposed to check some pixels, then check them again, if they do not differ then... <code>

if they do differ then <different code>

$temp and $temp2 match, but the condition that they dont match is run.

For $i = 1 To 9
    _Testfunc($i, "text")
Next

Func _Testfunc($Count, $sString)
    Local $acheck[2], $PicCheckValue, $temp, $temp2
    $acheck[0] = 20
    $acheck[1] = 30
    If $Count = 1 And $sString = "text" Then
        ConsoleWrite("$Count = " & $Count & " Setting $temp to Checksum of area tested " & $Count & @CRLF)
        $temp = PixelChecksum(10 + $acheck[0], 10 + $acheck[1], 10 + $acheck[0] + 10, 10 + $acheck[1] + 10)
        ConsoleWrite("$temp = " & $temp & @CRLF)
    EndIf
    $PicCheckValue = PixelChecksum(10 + $acheck[0], 10 + $acheck[1], 10 + $acheck[0] + 10, 10 + $acheck[1] + 10)
    ConsoleWrite("$PicCheckValue = " & $PicCheckValue & @CRLF)
    If $Count > 1 And $sString = "text" Then
        ConsoleWrite("$Count = " & $Count & @CRLF)
        $temp2 = $PicCheckValue
        ConsoleWrite("$temp2 = " & $temp2 & @CRLF)
        If $temp2 <> $temp Then
            ConsoleWrite("$temp and $temp2 do not match" & @CRLF)
            Return
        Else
            $temp = $temp2
        EndIf
    EndIf
    Return $PicCheckValue
EndFunc   ;==>_Testfunc

Cannot see the forest, for the trees.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

You need to debug better before posting :mellow: $temp and $temp2 do not match when you run the check. Run this code and you will see:

For $i = 1 To 9
    _Testfunc($i, "text")
Next

Func _Testfunc($Count, $sString)
    Local $acheck[2], $PicCheckValue, $temp, $temp2
    $acheck[0] = 20
    $acheck[1] = 30
    If $Count = 1 And $sString = "text" Then
;         ConsoleWrite("$Count = " & $Count & " Setting $temp to Checksum of area tested " & $Count & @CRLF)
        $temp = PixelChecksum(10 + $acheck[0], 10 + $acheck[1], 10 + $acheck[0] + 10, 10 + $acheck[1] + 10)
;         ConsoleWrite("$temp = " & $temp & @CRLF)
    EndIf
    $PicCheckValue = PixelChecksum(10 + $acheck[0], 10 + $acheck[1], 10 + $acheck[0] + 10, 10 + $acheck[1] + 10)
;     ConsoleWrite("$PicCheckValue = " & $PicCheckValue & @CRLF)
    If $Count > 1 And $sString = "text" Then
;         ConsoleWrite("$Count = " & $Count & @CRLF)
        $temp2 = $PicCheckValue
        ConsoleWrite("$temp = " & $temp & @CRLF)
        ConsoleWrite("$temp2 = " & $temp2 & @CRLF)
        If $temp2 <> $temp Then
            ConsoleWrite("$temp and $temp2 do not match" & @CRLF)
            Return
        Else
            $temp = $temp2
        EndIf
    EndIf
    Return $PicCheckValue
EndFunc   ;==>_Testfunc

It's very weird code though, I'm not sure why you use the $Count = 1 and $Count > 1 etc, but anyway... It's obvious why it fails => $temp is Local. The first run, $temp is set. The second run, $temp has no value anymore as it was discarded at the end of the function. Therefore, $temp is always empty. You can fix it using this:

Global $acheck[2], $PicCheckValue, $temp, $temp2
Link to comment
Share on other sites

Cheers dani.

I Altered the code to work (or not) on its own, so got mixed up.

The code was written like that because when in effect, its actually checking different locations and checks if the origional location matches when checked a second time.

Thanks again it was wrecking my head.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

This does pretty much the same as your code, except the first time it sets both instead of just one of the PixelChecksums. You can alter this of course but I thought this was better :mellow:

Test(10)

Func Test($Runs, $1 = False)
    Local $aCheck[2] = [20, 30]
    If Not $1 Then $1 = PixelChecksum(10 + $aCheck[0], 10 + $aCheck[1], 10 + $aCheck[0] + 10, 10 + $aCheck[1] + 10)
    $2 = PixelChecksum(10 + $aCheck[0], 10 + $aCheck[1], 10 + $aCheck[0] + 10, 10 + $aCheck[1] + 10)

    ConsoleWrite("$1 = " & $1 & " | $2 = " & $2 & @CR)
    If $1 <> $2 Then
        ConsoleWrite("$1 and $2 do not match" & @CR)
    Else
        If $Runs > 1 Then Test($Runs-1, $2)
    EndIf
EndFunc
Edited by dani
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...