Post[AHK] What is wrong with this script ?

Posts 12 of 2 · Page 1 of 1
[AHK] What is wrong with this script ?
Hey guys :P
So today i wanted to make an auto clicker with certain times inbetween the clicks.
I used the same base i use in all my scripts, but in this script, it doesnt work.
Maybe some people can help me, i cant find the mistakes i made ...
P.S. If this is in the wrong section, i didnt really know where to put this ... Move if necesairy :P
So heres the code :
Code:
;VARIABLES, here i declare the variable wich can be turned ON/OFF without exiting the programm 

   V_OnOff = 0

;On Off Trigger, determine wich buttons turn it ON/OFF

   F7::
   V_OnOff = 0
   Return

   F8::
   V_OnOff = 1
   Return

;Script, heres the actual script.

   If V_OnOff = 1
{
   Loop
{
   MouseClick, Left
   Sleep 500
   Send, {LButton Down}
   Sleep Sleep 1500
   Send, {LButton Up}
   Sleep 8000
   If (GetKeyState("LButton","P")=0)
{
   Break
   Return
}
}
}
}
It doesnt even make the first click ... :l So something is messed up, since this "base" works in other scripts ...
For anyone looking at this in the future:
At the first glance I see the error: a variable is being defined outside of a function - you can't do this in AHK as shown here.

(That is unless you:
import variables from a file, set the variable as global (e.g. "globalVar := "abc" or "global globalVar := "abc")
or you define the variables under #Persistent at the top of a script: (e.g. #Persistant [newline] fileName = C:\oof\filedir\LookAtTheAhkDocsFirst.txt)

The if statement is run, the value of the variable is None so the loop doesn't run as None != 1.

Take a look at the docs:
https://autohotkey.com/docs/Functions.htm
https://autohotkey.com/docs/Variables.htm

Also, because I was bored: here's the full corrected script:
Code:
   F7::
   V_OnOff = 0
   If V_OnOff = 1
   Loop
{
   MouseClick, Left
   Sleep 500
   Send, {LButton Down}
   Sleep Sleep 1500
   Send, {LButton Up}
   Sleep 8000
   If (GetKeyState("LButton","P")=0)
   Break
   return
}
   return

   F8::
   V_OnOff = 1
   If V_OnOff = 1
   Loop
{
   MouseClick, Left
   Sleep 500
   Send, {LButton Down}
   Sleep Sleep 1500
   Send, {LButton Up}
   Sleep 8000
   If (GetKeyState("LButton","P")=0)
   Break
   return
}
   Return
Posts 12 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?