Page 1 of 1

need help with a toggleable script to farm

Posted: 11 Apr 2024, 07:27
by Zekken
Im trying setup a script using AHK v2 to automatically harvest resources in the game . I dont exactly understand the syntax with autohotkey so im struggling to make the script . It work something like this

Press [x] key to toggle the script on and off
Press [p] key to switch between state one and state two

state one : holds left click and d at the same time
state two : holds left click and s at the same time

also to clarify i dont meant to completely stop the script but something more akin to this

Code: Select all

toggle := true
return

f1::toggle := !toggle   ;inverts toggle 0>1>0>1 etc.

#If toggle ;if toggle = true/1 then hotkeys work, otherwise disabled
z::a  ;this does not need a return since its single line
x::d

Re: need help with a toggleable script to farm

Posted: 11 Apr 2024, 08:06
by boiler
Make sure you're looking at the v2 documentation. It's #HotIf in v2, not #If like in v1. And your F1 function needs to declare toggle as global since it is assigning a value to it. It can't assume it's global.

Code: Select all

#Requires AutoHotkey v2.0

toggle := true

f1::global toggle := !toggle   ;inverts toggle 0>1>0>1 etc.

#HotIf toggle ;if toggle = true/1 then hotkeys work, otherwise disabled
z::a  ;this does not need a return since its single line
x::d

Re: need help with a toggleable script to farm

Posted: 11 Apr 2024, 08:08
by Zekken
Im well aware that the code is v1 i just found it as an example

Re: need help with a toggleable script to farm  Topic is solved

Posted: 11 Apr 2024, 08:12
by boiler
No matter how well aware you are of what that code is, what I said about looking at the v2 documentation is still good direction. That should be your first stop.