Jump to content

if, then, else, end if. advice please


Recommended Posts

$pixle2 = PixelSearch(389, 144, 436, 180, 0xCA372D)

If IsArray($pixle2) Then
    If PixelSearch(389, 144, 406, 162, 0xCA372D) Then
        MsgBox(1, "its Here", "its here")
    EndIf
Else
    MsgBox(1, "nothing", "Nothing")
EndIf

this code works when there is nothing found. but when it does find something, it doesn't pop up the msg box"its here". I know theres probably a simple soulution, but I can't see it. some help would be apricated.

Link to comment
Share on other sites

You have no else condition for your second "If" statement.

If the first If is true, and the second is false, the program goes on to the next statement without any message displayed.

Edit: In other words, it's not finding something (your target color value at that specific coordinate), but $pixle2 is an array.

Edited by Spiff59
Link to comment
Share on other sites

$pixle2 = PixelSearch(309, 145, 347, 179, 0xCA372D)

If IsArray($pixle2) Then
    If PixelSearch(309, 145, 323, 161, 0xCA372D) Then
        MsgBox(1, "its Here", "its here")
    Else
    EndIf
Else
    MsgBox(1, "nothing", "Nothing")
EndIf

I've added the end if. the point of the program is to locate the pixel in a generalized area, then localize the search to a smaller area. this time its not bringing up the Nothing MSGBOX, but it still won't display the its here MSGBOX. still confused.(as usuall)

Link to comment
Share on other sites

$pixle2 = PixelSearch(309, 145, 347, 179, 0xCA372D)

If IsArray($pixle2) Then
    If PixelSearch(309, 145, 323, 161, 0xCA372D) Then
        MsgBox(1, "its Here", "its here")
    Else
        ; <<<<<<<<<<<<<<  Let's see what we missed here ....
    EndIf
Else
    MsgBox(1, "nothing", "Nothing")
EndIf

Script logical fault in line marked with "<<<<<..."

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

the and really helped. but just out of curosity, how am I susposed to make it do an action only when the second part is false and the first part is true. like $pixle2 =true + the AND is false=do action 1

$pixle2=true + the AND is true=do action 2

$pixle2=false+the AND is false=do nothing

there can't be another out come since the second pixle search is a possible part of the picture its scaning. its rather confusing, all in all.

Link to comment
Share on other sites

$pixle2 = PixelSearch(389, 144, 436, 180, 0xCA372D)
If IsArray($pixle2) Then
$Temp = PixelSearch(389, 144, 406, 162, 0xCA372D)
If IsArray($Temp) Then
  MsgBox(1, "its Here", "its here")
EndIf
Else
MsgBox(1, "nothing", "Nothing")
EndIf

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

how am I susposed to make it do an action only when the second part is false and the first part is true. like

$pixle2 =true + the AND is false=do action 1

$pixle2=true + the AND is true=do action 2

$pixle2=false+the AND is false=do nothing

Work through it logically like this:

$pixle2 = PixelSearch(389, 144, 436, 180, 0xCA372D)
If IsArray($pixle2) Then
    $Temp = PixelSearch(389, 144, 406, 162, 0xCA372D)
    If IsArray($Temp) Then ; Both searches yielded results
        MsgBox(1, "Doing", "Action 2") ; Perform Action 2
    Else ; The previous If statement was false
        MsgBox(1, "Doing", "Action 1") ; Perform Action 1
    EndIf
Else ; This else statement is not needed (see the next version)
    MsgBox(1, "Not needed", "Nothing in particular") ; Code for doing nothing
EndIf

So we can simplify the above code to get:

$pixle2 = PixelSearch(389, 144, 436, 180, 0xCA372D)
If IsArray($pixle2) Then
    $Temp = PixelSearch(389, 144, 406, 162, 0xCA372D)
    If IsArray($Temp) Then
        MsgBox(1, "Doing", "Action 2") ; Perform Action 2
    Else
        MsgBox(1, "Doing", "Action 1") ; Perform Action 1
    EndIf
EndIf

OR (if you are not interested in the pixel's coordinates)

If IsArray(PixelSearch(389, 144, 436, 180, 0xCA372D)) Then
    If IsArray(PixelSearch(389, 144, 406, 162, 0xCA372D)) Then
        MsgBox(1, "Doing", "Action 2") ; Perform Action 2
    Else
        MsgBox(1, "Doing", "Action 1") ; Perform Action 1
    EndIf
EndIf
Edited by czardas
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...