Jump to content

Using While WEnd properly?


Recommended Posts

Ok. Someone told me on here that I have to use While WEnd for proper loops and not restart the script when I want to loop since its giving me overstack errors. However, when i tried to rewrite my script I ran into tons of problems.

Basicly , the example in the autoit help file says "If the expression is true the following statements up to the WEnd statement are executed. This loop continues until the expression is false.". The example makes sense however, the way I tried to do it which Im guessing I did not properly is the "While 1 WEnd" that I have been seeing in some example scripts on here and other places. Most the time the script could not find the matching While statements for WEnd etc. Spent couple hours trying to rewrite and rewrite but could not get it to work properly. I'd appreciate it a lot if someone could rewrite my script so that it would work the same but loops properly. Here it is, and thanks in advance.

WinActivate("program", "")

Sleep(3000)

main()

Func main()

$health = PixelGetColor (129,68)

If $health = 238080 Then

Send("{TAB}")

Else

Sleep(1000)

main()

EndIF

$target = PixelGetColor (92,103)

If $target = 10132890 Then

Sleep(1000)

Else

main()

EndIf

$tofar = PixelGetColor (447,51)

If $tofar = 3276800 Then

Send("{TAB}")

main()

Else

Sleep(1000)

EndIf

Send("7")

Sleep(3000)

Send("=")

Sleep(1000)

$i = 0

While $i <= 2

Send("4")

Sleep(2100)

Send("5")

Sleep(2100)

Send("6")

Sleep(2100)

Send("7")

Sleep(2100)

Send("8")

Sleep(2100)

$i = $i + 1

WEnd

Sleep(1000)

Call("main")

EndFunc

Link to comment
Share on other sites

This should work. I contained the entire function in one big infinite While loop and use ContinueLoop when you want it to go to the start.

WinActivate("program", "")
Sleep(3000)

main()


Func main()

    While 1

        $health = PixelGetColor (129,68)
        If $health = 238080 Then
            Send("{TAB}")
        Else
            Sleep(1000)
            ContinueLoop
        EndIF


        $target = PixelGetColor (92,103)
        If $target = 10132890 Then
            Sleep(1000)
        Else
            ContinueLoop
        EndIf

        $tofar = PixelGetColor (447,51)
        If $tofar = 3276800 Then
            Send("{TAB}")
            ContinueLoop
        Else
            Sleep(1000)
        EndIf

        Send("7")
        Sleep(3000)
        Send("=")
        Sleep(1000)
        $i = 0
        While $i <= 2
            Send("4")
            Sleep(2100)
            Send("5")
            Sleep(2100)
            Send("6")
            Sleep(2100)
            Send("7")
            Sleep(2100)
            Send("8")
            Sleep(2100)
            $i = $i + 1
        WEnd
        Sleep(1000)

    WEnd

EndFunc
Edited by Larry
Link to comment
Share on other sites

For some reason that script doenst work, Its running and no errors but it doesn't do what its told and I double checked the cordinates and dec colors. :/

The example that comes with AutoIT help file makes total sense to me

$i = 0

While $i <= 10

MsgBox(0, "Value of $i is:", $i)

$i = $i + 1

WEnd

When the expression becomes false it will stop looping. I can grasp this example and concept.

I dont however understand how the While 1 script operates.

I have very minimal knowlege of this stuff as you can see, infact I only picked it up 2 days ago for the first time. (Did some simple VB 2 years ago in Computer Tech Class). I do appreciate all the help so far :P With your help I'll be able to finish my script :lmao:

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