like imagesearch will return a value for success or fail
and we read the value of ErrorLevel to get it
is ErrorLevel a reserved word ?
Re: is ErrorLevel a reserved word ?
Yes it is. It seems like you already know that it is.
Re: is ErrorLevel a reserved word ?
But you can set the variable yourself until it gets overwritten again by some command that sets it... so yeah, that qualifies as reserved, imho. Perhaps not in the strictest sense, but mostly partly - at least for variable usage You could have a ErrorLevel() custom function or ErrorLevel as a literal label name, for example - that should be okay... Edit: okay in the sense of possible, but not recommended
Re: is ErrorLevel a reserved word ?
I was considering it reserved because you can't name your own variable ErrorLevel, but you're right that you won't actually get an error if you try using it. Just like I would consider Clipboard reserved, but I suppose you could use it for non-clipboard reasons at your own peril.
Re: is ErrorLevel a reserved word ?
- AFAIK, in AHK v1, A_Args and ErrorLevel are normal super-global variables. But I would avoid considering/treating them as regular variables.
- (You can define a variable as super-global by doing global var := "value" outside of a function definition.)
- (In AHK v1, you cannot write to built-in variables, with at least these exceptions: A_Args, Clipboard, ErrorLevel.)
- Trying to use ErrorLevel as a normal variable would be awkward because it can be altered by various functions/commands. You'd have to be careful to avoid it being overwritten.
- To take the question literally, I might define a reserved keyword as a word that you can't use as a variable name. By that definition, you can use ErrorLevel as a variable name, so it's not reserved. (But I would avoid considering/treating it as a regular variable.)
- (You can define a variable as super-global by doing global var := "value" outside of a function definition.)
- (In AHK v1, you cannot write to built-in variables, with at least these exceptions: A_Args, Clipboard, ErrorLevel.)
- Trying to use ErrorLevel as a normal variable would be awkward because it can be altered by various functions/commands. You'd have to be careful to avoid it being overwritten.
- To take the question literally, I might define a reserved keyword as a word that you can't use as a variable name. By that definition, you can use ErrorLevel as a variable name, so it's not reserved. (But I would avoid considering/treating it as a regular variable.)
Last edited by jeeswg on 30 Sep 2019, 21:06, edited 4 times in total.
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
Re: is ErrorLevel a reserved word ?
I would see it as misleading to define it that way and advise someone that it is not reserved. That will only lead to problems. You might say you define it that way but would not advise using it, which brings the value of that definition into question.
Re: is ErrorLevel a reserved word ?
- And what about your first post? Is that misleading? ErrorLevel has a special role, but is not a reserved keyword. (Admittedly, the title seems to ask, is it reserved, and the OP seems to ask, does it have a special role.)
- To your point, I advised against using ErrorLevel as a regular variable in my original edit!? (Anyhow, I've now repeated the point at the end of my post in parentheses.)
- Actually, ErrorLevel has a legitimate use case that doesn't seem to have been mentioned, you assign to it within functions, to report error/success. I.e. it's nature requires that it be somewhat like a regular variable.
- A borderline legitimate use case for ErrorLevel as a regular variable, would be with callback functions, e.g. a comparator function for the Sort command. To supply extra information to the comparator function.
- To your point, I advised against using ErrorLevel as a regular variable in my original edit!? (Anyhow, I've now repeated the point at the end of my post in parentheses.)
- Actually, ErrorLevel has a legitimate use case that doesn't seem to have been mentioned, you assign to it within functions, to report error/success. I.e. it's nature requires that it be somewhat like a regular variable.
- A borderline legitimate use case for ErrorLevel as a regular variable, would be with callback functions, e.g. a comparator function for the Sort command. To supply extra information to the comparator function.
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
Re: is ErrorLevel a reserved word ?
Run this two-line script on AHK v1, and it lists A_Args and ErrorLevel:
Here's a script to test if variables are writable:
A list of built-in variables:
list of every command/function/variable from across all versions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=74&t=27321&p=131642#p131642
Some more info re. built-in variables:
C++: AHK source code: VarIsInit - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=75&t=65308
Code: Select all
ListVars
MsgBox
;AHK v1:
;0, A_Args
;ErrorLevel
;AHK v2:
;A_Args
;Array, Class, Map, Object
;ErrorLevel
Code: Select all
;test if variables are writable
vList := " ;continuation section
(
A_Args
A_Now
Clipboard
ErrorLevel
)"
vOutput := ""
Loop Parse, vList, % "`n", % "`r"
{
try
{
%A_LoopField% := "abc"
vOutput .= "`t" A_LoopField "`r`n"
}
catch
vOutput .= A_LoopField "`r`n"
}
Clipboard := vOutput
MsgBox, % "done"
return
list of every command/function/variable from across all versions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=74&t=27321&p=131642#p131642
Some more info re. built-in variables:
C++: AHK source code: VarIsInit - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=75&t=65308
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: No registered users and 394 guests