Hey, I am a beginner with AHK the language. I made a script but is doesnt work. I didnt know a fitting subject.
The error is:
unexpected "}" at 011
This is the script:
Toggle = "off"
GetKeyState, state, f
if state = D {
if (Toggle = "off")
Toggle = "on"
else
Toggle = "off"
}
Loop {
if (toggle = "on") {
click
sleep 40
}
}
p::
ExitApp
Beginner Script Not Working Topic is solved
Re: Beginner Script Not Working Topic is solved
The line if state = D { doesn't work like you expect.
Unlike your other ifs (which use expression-style if syntax), this is "traditional" if syntax and the trailing, opening { is not allowed here on the same line. (AHK thinks here that you want to use the string D { for the comparison). Hence, the closing } a bit later is "unexpected" - it is missing its opening brace. Either use also expression syntax here: if (state = "D") { (recommended) - or put the opening brace on the next line:
compare ( https://autohotkey.com/docs/commands/If ... on.htm#otb )
Unlike your other ifs (which use expression-style if syntax), this is "traditional" if syntax and the trailing, opening { is not allowed here on the same line. (AHK thinks here that you want to use the string D { for the comparison). Hence, the closing } a bit later is "unexpected" - it is missing its opening brace. Either use also expression syntax here: if (state = "D") { (recommended) - or put the opening brace on the next line:
Code: Select all
if state = D
{
Last edited by gregster on 23 Apr 2018, 11:44, edited 2 times in total.
Re: Beginner Script Not Working
Also, change the Toggle = "off" assignment to Toggle := "off". The same goes for Toggle = "on" to Toggle := "on" . But only the ones which are not in the if statements - there you want to compare, not to assign like with variables.
Same problem here like above - confusion between traditional and expression syntax for assigning variables: https://autohotkey.com/docs/Variables.htm
Try to always use expression syntax for ifs and assigning variables.
Same problem here like above - confusion between traditional and expression syntax for assigning variables: https://autohotkey.com/docs/Variables.htm
Try to always use expression syntax for ifs and assigning variables.
Re: Beginner Script Not Working
Ok thanks man! Now I have this, but it is still not clicking when I press the "f" button.
Toggle := "off"
GetKeyState, state, f
if (state = "D") {
if (Toggle = "off") {
Toggle = "on"
}
else {
Toggle = "off"
}
}
Loop {
if (toggle = "on") {
click
sleep 40
}
}
p::
ExitApp
Toggle := "off"
GetKeyState, state, f
if (state = "D") {
if (Toggle = "off") {
Toggle = "on"
}
else {
Toggle = "off"
}
}
Loop {
if (toggle = "on") {
click
sleep 40
}
}
p::
ExitApp
Re: Beginner Script Not Working
You still didn't change all variable assignments to the right syntax (you changed one, but missed two). Try to use = only for if-comparisons (or == for case-sensitive comparisons).
I don't know your exact use case. I assume it has to do with gaming - about which I know nothing (well, a little some time ago... but not in combination with AHK, anyway).
But I guess that your script is not ideal for what you have in mind. I would rather try something like this:
This works for me, but depending on your game it perhaps might not...
(Note that I added more time between the clicks for my testing.)
I don't know your exact use case. I assume it has to do with gaming - about which I know nothing (well, a little some time ago... but not in combination with AHK, anyway).
But I guess that your script is not ideal for what you have in mind. I would rather try something like this:
Code: Select all
f::
Sleeptime := 2000 ; milliseconds between clicks
toggle := !toggle ; well... a toggle
SetTimer clickit, % toggle ? Sleeptime : "off" ; Starts a timer that calls the function clickit() in the above defined time steps - or stops it, if it is already running.
return
clickit() { ; a function definition
click
}
p::ExitApp
(Note that I added more time between the clicks for my testing.)
Who is online
Users browsing this forum: Descolada and 319 guests