Jump to content
Sign in to follow this  
Pyrex

If...ElseIf...Else

Recommended Posts

Pyrex

I having a problem with this:

If PixelGetColor(328,84) <> 41216 Then
Send ("{TAB}")
EndIf
If ((PixelGetColor(328,84) = 41216) And (PixelGetColor(254,977) = 10066329)) Then
Send ("1")
Sleep(1700)
Else
    Sleep(1700)
    Send("{UP down}")
    Sleep (3000)
    Send("{UP up}")
    Sleep(5000)
EndIf

As you can see, I firstly want it to check and see if it's got the colour. Then if not, it will Tab.

Then the second part I need it to check 2 colours and they need to both be there, otherwise I want it to press UP for 3 seconds.

I can see on my screen that they are both there, but it just seems to skip to the 'Else' part.

I'm a bit confused as if it's Else or ElseIf. I'm not sure what the difference is.

Share this post


Link to post
Share on other sites
sandin
GEOSoft

I having a problem with this:

If PixelGetColor(328,84) <> 41216 Then
Send ("{TAB}")
EndIf
If ((PixelGetColor(328,84) = 41216) And (PixelGetColor(254,977) = 10066329)) Then
Send ("1")
Sleep(1700)
Else
    Sleep(1700)
    Send("{UP down}")
    Sleep (3000)
    Send("{UP up}")
    Sleep(5000)
EndIf

As you can see, I firstly want it to check and see if it's got the colour. Then if not, it will Tab.

Then the second part I need it to check 2 colours and they need to both be there, otherwise I want it to press UP for 3 seconds.

I can see on my screen that they are both there, but it just seems to skip to the 'Else' part.

I'm a bit confused as if it's Else or ElseIf. I'm not sure what the difference is.

They might both be there but are they at the coordinates you gave?

Easy test.

MsgBox(0, "TEST", PixelGetColor(328,84))
MsgBox(0, "TEST", PixelGetColor(254,977))
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Pyrex

They might both be there but are they at the coordinates you gave?

Easy test.

MsgBox(0, "TEST", PixelGetColor(328,84))
MsgBox(0, "TEST", PixelGetColor(254,977))
yeah both are correct

Share this post


Link to post
Share on other sites
GEOSoft

yeah both are correct

I suspect that you need a sleep after the first If. You are sending the tab but I think before it gets a chance to change you checking the pixels. Try

Local $a = 0, $b = 0
If ((PixelGetColor(328,84) = 41216) And (PixelGetColor(254,977) = 10066329)) Then
$a = PixelGetColor(328,84)
$b = PixelGetColor(254,977)
Send ("1")
Sleep(1700)
Else
    Sleep(1700)
    Send("{UP down}")
    Sleep (3000)
    Send("{UP up}")
    Sleep(5000)
EndIf
MsgBox(0, "TEST", $a & @CRLF & $b)
That should tell you pretty much for sure. Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Pyrex

I suspect that you need a sleep after the first If. You are sending the tab but I think before it gets a chance to change you checking the pixels. Try

Local $a = 0, $b = 0
If ((PixelGetColor(328,84) = 41216) And (PixelGetColor(254,977) = 10066329)) Then
$a = PixelGetColor(328,84)
$b = PixelGetColor(254,977)
Send ("1")
Sleep(1700)
Else
    Sleep(1700)
    Send("{UP down}")
    Sleep (3000)
    Send("{UP up}")
    Sleep(5000)
EndIf
MsgBox(0, "TEST", $a & @CRLF & $b)
That should tell you pretty much for sure.
It presses 1 then brings up the message box saying "41216 10066329"

Share this post


Link to post
Share on other sites
PsaltyDS

It presses 1 then brings up the message box saying "41216 10066329"

...and what did you want it to do? Those values indicate the If condition was satisfied, so it did what it was coded to do. What else did you want it to do...?

Your first post started out with testing only one of the pixels, and only for "<>". Then you tested for "=" on two pixels. What is the relationship between the two? Is hitting TAB supposed to change the pixel color so it could match on the next test, or are they unrelated? If the first pixel was "<>", then did you need to text the second one at all?

:)


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
GEOSoft

I suspect that If you change the code that I gave you to what is below, you will find that the Else is in fact NOT being triggered which is what you wanted.

;
Local $a = 0, $b = 0, $c = 0
If ((PixelGetColor(328,84) = 41216) And (PixelGetColor(254,977) = 10066329)) Then
$a = PixelGetColor(328,84)
$b = PixelGetColor(254,977)
Send ("1")
Sleep(1700)
Else
    Sleep(1700)
    Send("{UP down}")
    Sleep (3000)
    Send("{UP up}")
    Sleep(5000)
    $c = 1
EndIf
MsgBox(0, "TEST", $a & @CRLF & $b & @CRLF & $c)
;

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Pyrex

I want it to:

Firstly, it won't have a selected target. So the colour will be different than 41216. So therefore it has to press tab (which is the button to select a target), (Which is what I want it to do).

Then, I want it to make sure it's selected the target. So it will check for 41216 and it should be true.

Then I want it to make sure the target is not out of range. By searching for the colour 10066329.

If both colours are true, I want it to start attacking (1).

If either one is false, I want it to run (up key) for 3 seconds, then start from the top.

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.