Not a bug, but a pitfall of
the "legacy" syntax, in which you will have to
escape certain characters (like a literal "%"), if they aren't unambigious:
First of all,
variable assignment with
= ("legacy method") instead of
:= ("
expression method") is deprecated and ideally shouldn't be used anymore (it's still there for backwards compatibility, but will be discontinued in AHK v2).
If you use it, you should use spaces around the = (at least one), otherwise it could happen, in combination with a trailing
:, that it is seen as a label name, because the naming conventions for
labels are rather generous:
https://www.autohotkey.com/docs/misc/Labels.htm#syntax-and-usage wrote:LabelName:
To create a label, write the label name followed by a colon as shown above. Aside from whitespace and comments, no other code can be written on the same line.
Names: Label names are not case sensitive, and may consist of any characters other than space, tab, comma and the escape character (`). However, due to style conventions, it is generally better to use only letters, numbers, and the underscore character (for example: MyListView, Menu_File_Open, and outer_loop).[...]
As demonstrated here:
Code: Select all
gosub hello=world
hello =world: ; this assigns literal text, like also hello = world:
msgbox % hello
Exitapp
hello=world: ; this a label name
msgbox label was called
return
Or, you just escape the trailing
: with
AHK's escape character ` to make clear that this isn't a label name, but a variable assignment.
Code: Select all
hello=world`: ; variable assignment
msgbox % hello
Exitapp
(The syntax highlighter of the codebox isn't smart enough to see that this isn't a label. Btw, you seemed to have difficulties in using the codebox. Just put
[code][/code]-tags around your code; there is also a button for it, in the editor: fifth from the left. I fixed it for you in your post above.)