In the help I have found :
1) "Scripts can be commented by using a semicolon at the beginning of a line. For example:
; This entire line is a comment. "
When the line is indented does "the beginning of a line" mean the first non blank character not taking into account tab or space ?
2) "Comments may also be added to the end of a command, in which case the semicolon must have at least one space or tab to its left. For example:
Run Notepad ; This is a comment on the same line as a command. "
What is the definition of "command" ? Does this mean any "entry" in "Alphabetical Command and Function Index" of the help ? this is broader and include true commands, functions, #strings and block object array delimiters ?
e.g. for a block
{ ; comment
...
} ; comment
3) Storing values in variables are missing in the list
e.g.
CopyOfVar = %Var% ; With the = operator, percent signs are required to retrieve a variable's contents.
4) "In addition, the /* and */ symbols can be used to comment out an entire section, but only if the symbols appear at the beginning of a line as in this example:
/*
MsgBox, This line is commented out (disabled).
MsgBox, This one too.
*/ "
Same question as in 1)
Clarifications on comments in Scripts
Re: Clarifications on comments in Scripts
Yes. AHK will, under most circumstances (I don't feel confident in saying all circumstances), I think there are some exceptions) ignore the whitespace at the beginning or end of a line - AHK leading whitespace or trailing whitespace.When the line is indented does "the beginning of a line" mean the first non blank character not taking into account tab or space ?
While command would be something like Run, WinWait, MsgBox, etc. per the documentation, you can add comments on lines that are doing maths like var:=8+2. Whether assigning a variable a value is technically a command or not may be a matter of semantics. My experience with writing comments in AHK is if you type ; (note the preceeding whitespace) then anything after that on any line is going to be ignored by AHK.What is the definition of "command" ?
I'm not sure if your point/question 3 is really a question to be answered.
Yes, you can have whitespace preceding these characters and they will still function. Like in 1, that leading whitespace is just ignored by AHK./* ...
Re: Clarifications on comments in Scripts
Using sCiTe4AutoHotkey can be helpful in visually understanding the comments.
See an example I made;
https://gyazo.com/9601dac59956dd36a9cce49fce22aaaa
See an example I made;
https://gyazo.com/9601dac59956dd36a9cce49fce22aaaa
Re: Clarifications on comments in Scripts
Last edited by BoBo on 29 Jul 2017, 08:05, edited 1 time in total.
Re: Clarifications on comments in Scripts
@BoBo
That doesn't work for single lines.
If it did, then MsgBox Hi would be executed. But it is actually treated as part of the comment.
That doesn't work for single lines.
Code: Select all
!3::
/* Testing */
MsgBox Hi
*/
MsgBox Bye
return
Re: Clarifications on comments in Scripts
To explain semicolons and comments, I would say this:
- if the line starts with a semicolon, the whole line is a comment
- if in a line a space/tab is followed by a semicolon, everything from that point in the line onwards is a comment
- this applies everywhere except for continuation sections (see example code below)
- the simple logic of this makes it very easy to remove comments from a script, or to distinguish between code and comments if you want to do some parsing (e.g. converting a script from AHK v1 to AHK v2)
==================================================
Some other points:
- to have a literal space/tab and a semicolon, escape the semicolon with a backtick
- to have a semicolon hotkey, escape the semicolon with a backtick
In this post is everything I think is worth saying about semicolon comments in AutoHotkey, unless someone can find anything I've missed!? Cheers.
==================================================
'if 0' and '#If 0' are handy for temporarily commenting things out:
Well, that's it for my comments on comments.
- if the line starts with a semicolon, the whole line is a comment
- if in a line a space/tab is followed by a semicolon, everything from that point in the line onwards is a comment
- this applies everywhere except for continuation sections (see example code below)
- the simple logic of this makes it very easy to remove comments from a script, or to distinguish between code and comments if you want to do some parsing (e.g. converting a script from AHK v1 to AHK v2)
Code: Select all
#IfWinActive, ahk_class Notepad ;COMMENT
q:: ;COMMENT you can comment everywhere
;COMMENT
;COMMENT
MsgBox, % "hello world" ;COMMENT
vText := StrReplace("hello", "l", "", vCount) ;COMMENT
MsgBox, % vText " " vCount ;COMMENT
Loop, 3 ;COMMENT
{ ;COMMENT
var++ ;COMMENT
} ;COMMENT
var += 5 ;COMMENT
MsgBox, % var ;COMMENT
vText := "abcde" ;COMMENT
return ;COMMENT
#IfWinActive ;COMMENT
;==================================================
w:: ;continuation sections and comments
vText := "
(
abcde ;this is not comment
abcde ;this is not comment
abcde ;this is not comment
)"
MsgBox, % "[" vText "]"
vText := "
(Comments
abcde ;this is a comment
abcde ;this is a comment
abcde ;this is a comment
)"
MsgBox, % "[" vText "]"
return
Some other points:
- to have a literal space/tab and a semicolon, escape the semicolon with a backtick
- to have a semicolon hotkey, escape the semicolon with a backtick
Code: Select all
q:: ;escaping semicolons, to have a literal space/tab and a semicolon
;the line below would be invalid, 'Missing close-quote' error:
;vText := "a ; b ; c"
;the line is OK if we escape the semicolons:
vText := "a `; b `; c"
MsgBox, % vText
return
;==================================================
;because a semicolon at the start of a line
;is interpreted as a comment,
;to do a semicolon hotkey, we escape the semicolon:
`;:: ;a semicolon hotkey
MsgBox, % A_ThisHotkey
return
==================================================
'if 0' and '#If 0' are handy for temporarily commenting things out:
Code: Select all
#If 0
q::
MsgBox, % A_ThisHotkey
return
#If
;==================================================
w::
if 0
{
MsgBox, % "a"
MsgBox, % "b"
MsgBox, % "c"
}
MsgBox, % "d"
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Who is online
Users browsing this forum: AdsBot [Google], Bing [Bot], Google [Bot], Spawnova and 98 guests