Sign in to follow this  
Followers 0
oozma

While statement

7 posts in this topic

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

I love you :unsure: saved me such a headache... other programs I've used are so different :P

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Thank you much :unsure: but when I compile, the start and quit hotkeys work but stop does nothing. It keeps running even after Alt+2 :P

Share this post


Link to post
Share on other sites

Thank you much :unsure: but when I compile, the start and quit hotkeys work but stop does nothing. It keeps running even after Alt+2 :P

After stop it finishes all three already running functions.

It can be checked $running state also inside these functions to stop immediatelly.

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