Sign in to follow this  
Followers 0
Rozar

Help with IFs and an option to switch

11 posts in this topic

I am new to Autoit so I am still learning the basics. I did look for 2 hours in the Autoit help and in this forum but was not able to find a solution to my problem.

What I want to do is similar to searching the right and left side of 2 pages for a certain color. Note only 1 of the sides of 1 of the pages will ever be this color and 1 of the sides of 1 of the pages will always be this color. So the color does exsist and it will never be more than 1 of the 4 options.

Sorta like this:

;Page 1 first

If right side is green Then

Perform action

End If

If left side is green Then

Perform action

End If

(This is part I can not figure out)

If neither the right or left side of page 1 is green then switch to page 2 and test again. If either the right or left side of page 1 was found to be green then skip the next 2 Ifs.

;this would search page 2

If right side is green Then

Perform action

End If

If left side is green Then

Perform action

End If

How would I do this?

Thanks for your help

Rozar

Share this post


Link to post
Share on other sites



Welcome Rozar,

Let's see if I can work with your dream code.

Code as below with an If block shows:

  • If right side is green then execute condition and then exit If block. If false, then test next condition.
  • If left side is green then execute condition and then exit If block. If false, then test next condition.
  • If all false conditons above, then execute condition.
If right side is green Then ; test 1st condition and if true, then perform action.
    Perform action
ElseIf left side is green Then ; test 2nd condition (only if 1st condition was false)
    Perform action
Else ; Use 3rd condition (only if all above conditions were false)
    Switch page
EndIf

:D

Share this post


Link to post
Share on other sites

you might want to see help on

PixelSearch()

to search the area(s) for the green color

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

If right side is green Then ; test 1st condition and if true, then perform action.

Perform action

ElseIf left side is green Then ; test 2nd condition (only if 1st condition was false)

Perform action

Else ; Use 3rd condition (only if all above conditions were false)

Switch page

EndIf

I cant get this to work either because it would need to look like this:

If right side is green Then ; test 1st condition and if true, then perform action.

Perform action

ElseIf left side is green Then ; test 2nd condition (only if 1st condition was false)

Perform action

Else ; Use 3rd condition (only if all above conditions were false)

Switch page (this is where I am having the problem, It stops after switch page)

If right side is green Then ; test 1st condition and if true, then perform action.

Perform action

Else left side is green Then ; test 2nd condition (only if 1st condition was false)

Perform action

EndIf

EndIf

you might want to see help on

PixelSearch()

to search the area(s) for the green color

8)

I am not having problems with PixelSearch. I can find the color.

Share this post


Link to post
Share on other sites

While 1
    If right side is green Then ; test 1st condition and if true, then perform action.
        Perform action
        ExitLoop ; Take this out if you want it to loop forever
    ElseIf left side is green Then ; test 2nd condition (only if 1st condition was false)
        Perform action
        ExitLoop ; Take this out if you want it to loop forever
    Else ; Use 3rd condition (only if all above conditions were false)
        If page is 1 Then
            Switch to page 2
        ElseIf page is 2 Then
            Switch to page 1
        EndIf
    EndIf
WEnd


Ha, I haven't been on these forums since... 2006, almost. Behold, my legacy signature:My AutoIt idol is Valuater. You know you love him, too.My Stuff: D&D AGoT Tools Suite

Share this post


Link to post
Share on other sites

I made this real simple to show what I am having a problem with, I can check page 1 for the Checksum and if its true this works fine. Its when page 1 does not have the Checksum that is the problem. I send the "W" key to change the page and the process ends without checking for the checksum again. I need it to restart again at the "If" and check for the Checksum on page 2. The Checksum will always either be on page 1 or 2 and is always in the same place. I just need to know which page and perform the mouse clicks on that page.

$ClickDelay = 800

$checksum = PixelChecksum(448, 153, 452, 157) ; left side of page Pixel Check

$yes = 1

While $yes

If $checksum = 1443501671 Then ; this part works if this is true is does action and exits

MouseClick ("left", 450, 160, 1, 1)

Sleep($ClickDelay)

MouseClick ("left", 250, 250, 1, 1)

Sleep($ClickDelay)

ExitLoop

Else

Send("{w}") ;this part does NOT work, it stops here and does not start again at "If"

Sleep($ClickDelay)

$yes = 0

EndIf

WEnd

Im still new at this but for the life of me I cant make autoit send a command (in this case the "w" key to change the page and then do the "If" process again.

Thanks for the help

Rozar

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

need to place this line

$checksum = PixelChecksum(448, 153, 452, 157) ; left side of page Pixel Check

just after the while $yes... not before

8)

EDIT ...

also, $yes = 0 makes the loop end

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

need to place this line

$checksum = PixelChecksum(448, 153, 452, 157) ; left side of page Pixel Check

just after the while $yes... not before

8)

EDIT ...

also, $yes = 0 makes the loop end

8)

Thank you for the help, it now works :D

Rozar

Im sure I will be back with more newb question

Share this post


Link to post
Share on other sites

Welcome...

we like to help people that try...

your effort was fine

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

As a follow up, this script is for a game and sometimes lag can do funny things. Would there be a way to limit the number of times the above script would loop? 2 would be enough. Then have it stop.

Rozar

Share this post


Link to post
Share on other sites

As a follow up, this script is for a game and sometimes lag can do funny things. Would there be a way to limit the number of times the above script would loop? 2 would be enough. Then have it stop.

Rozar

Dim $i=0

While $i< 2
;Rest of script
$i=$i+1
Wend

That with repaet anything in the "Rest of script" 2 times

(I would have made the whole code for you, but my copy and paste is broken on mozilla FF) :">

Hope that helps

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  
Followers 0