Over the years I have helped many people with learning/debugging AutoHotkey in forums and one of the most common areas where people have issues (confusion) while learning AutoHotkey is with the difference between the assignment & expression operators '=' & ":=" respectively. Both can assign value, but the former is purely assignment; the latter is used for any expression (code to be executed/evaluated).
- varName = Any unquoted string.
- varName = %anotherVarName%
- varName := "Any quoted string."
- varName := anotherVarName
- varName := !anotherVarName?0:255
- varName := !anotherVarName?"Yes":"No"
- varName := ((anotherVarName == "whatImTestingFor")?"Value exists":"Value doesn't exist")
- Doesn't use quotation marks for strings.
- Variable names must be wrapped with %%.
- Needs quotation marks for strings.
- Variable names don't need to be wrapped.
- Can contain any possible expression operation in the language.
In my opinion there's only one use for '=' ever. :
'=' can be used to strip leading and trailing spaces from variables
- E.g. varName := " String with spaces "
- varName = %varName%
- Result: varName == "String with spaces"
Everything else can always be done with ':='. That, of course, is your preference.
This is my first post here & I'm very aware of the hate for AHK by many so I will write my disclaimer here once.
Even though I know quite a few other languages I will always be an AutoHotkey advocate.
Many people do not like the chaotic syntax of AHK, but once you understand it & create your own consistent style it's actually quite nice (IMO?). I am aware of it's inadequecies in certain areas, but like many other languages it is still useful for many things (We can even plug in to UWP with Selenium now :D).