Jump to content

While statement


oozma
 Share

Recommended Posts

Hi All,

First time creating an AutoIT script here. Below is a code that I've made, but I keep returning the error of:

REF: missing Wend.

While

^

ERROR: syntax error

WEnd

I've read through help and many threads, I'm not sure what I'm doing wrong... :/ Can anyone help? Thank you.

While 1 = 1

    call ("hs")

    Func HS()

    $hc = 0
        Do
            Send (1)
            sleep(100)
            MouseClick("Right")
            sleep(5000)
            $hc = $hc + 1
        Until $hc = 1

    EndFunc

    Call ("MM")

    Func MM()

    $mc = 0
        Do  
    
            Send(8)
            sleep(100)
            MouseClick("Left")
            sleep(2200)
            $mc = $mc + 1
        Until $mc = 22
    
    EndFunc
WEnd
Link to comment
Share on other sites

The body of functions shouldn't be in any kind of loops.

While 1 
    Call ("hs")
    Call ("MM")
WEnd

Func HS()
$hc = 0
    Do
        Send (1)
        sleep(100)
        MouseClick("Right")
        sleep(5000)
        $hc = $hc + 1
    Until $hc = 1
EndFunc

Func MM()
    $mc = 0
    Do   
        Send(8)
        sleep(100)
        MouseClick("Left")
        sleep(2200)
        $mc = $mc + 1
    Until $mc = 22
EndFunc

When the words fail... music speaks.

Link to comment
Share on other sites

Sorry again for a question, how about...

The hotkeys of !1 and !2 don't start or stop the script. It seems to stop instantly by itself :P I'm assuming it's something like... no while inside of a function. Thank you again for any help someone can offer.

HotKeySet ("!1","Start")
HotKeySet ("!2","Stop")

Func Start()
While 1
    Call ("hs")
    Call ("MM")
    Call ("R") 
WEnd
EndFunc


Func Stop()
    ExitLoop
EndFunc;==> Quit


Func HS()
$hc = 0
    Do
        Send (1)
        sleep(50)
        MouseClick ("Right")
        sleep(5000)
        $hc = $hc + 1
    Until $hc = 1
EndFunc;==> HS

Func MM()
    $mc = 0
    Do  
        Send(8)
        sleep(50)
        MouseClick ("Left")
        sleep(2200)
        $mc = $mc + 1
    Until $mc = 3
EndFunc;==> MM

Func R()
    Send (0)
    sleep(50)
    MouseClick ("Left")
    sleep(230000)
EndFunc;==> Resting
Link to comment
Share on other sites

No need to use Call() in this case.

HotKeySet ("!1","Start")
HotKeySet ("!2","Stop")
HotKeySet ("!3","Quit")

Global $running = False

While 1
 If $running Then
    HS()
    MM()
    R()
 EndIf
 Sleep(100)
WEnd

Func Start()
 $running = True
EndFunc

Func Stop()
 $running = False
EndFunc

Func Quit()
 Exit
EndFunc

Func HS()
 $hc = 0
    Do
       Send (1)
       sleep(50)
       MouseClick ("Right")
       sleep(5000)
       $hc = $hc + 1
    Until $hc = 1
EndFunc;==> HS

Func MM()
    $mc = 0
    Do    
       Send(8)
       sleep(50)
       MouseClick ("Left")
       sleep(2200)
       $mc = $mc + 1
    Until $mc = 3
EndFunc;==> MM

Func R()
    Send (0)
    sleep(50)
    MouseClick ("Left")
    sleep(230000)
EndFunc;==> Resting
Edited by Zedna
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...