Assistance with local variables

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Pumpk11nnn
Posts: 1
Joined: 27 Mar 2024, 17:38

Assistance with local variables

27 Mar 2024, 17:46

Hey, I'm pretty new to AHK, but I've been coding in python and lua for a little while, so I'm trying to understand what is causing this script to not update the local variables.

Code: Select all

delaySpeed := 1000
mashSpeed := 15
currentSpeed := 15

x::
toggle:=!toggle
if (toggle)
    currentSpeed := delaySpeed
else
    currentSpeed := mashSpeed
return

~$LButton::
    While GetKeyState("LButton", "P"){
        Click
    Sleep currentSpeed
    }
return
I'm assuming the issue is I'm not supposed to be doing := or something inside of the if statement, and I've tried looking around for examples, yet here I sit dumbfounded.
If anyone could help me out I would appreciate it!
User avatar
boiler
Posts: 16978
Joined: 21 Dec 2014, 02:44

Re: Assistance with local variables

27 Mar 2024, 18:07

You have no local variables. In v1, hotkey subroutines are not functions. You variable is being updated. You can see for yourself:

Code: Select all

delaySpeed := 1000
mashSpeed := 15
currentSpeed := 15

x::
toggle:=!toggle
if (toggle)
    currentSpeed := delaySpeed
else
    currentSpeed := mashSpeed
return

~LButton::
    MsgBox % currentSpeed
return

Your script works just as you would expect (at least that's what I would think you were expecting it to do). Test it in MS Paint and hold your mouse down while moving a brush and you can see the difference.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 199 guests