is ErrorLevel a reserved word ?

Get help with using AutoHotkey and its commands and hotkeys
takayo97
Posts: 43
Joined: 09 Jun 2018, 16:30

is ErrorLevel a reserved word ?

30 Sep 2019, 17:45

like imagesearch will return a value for success or fail
and we read the value of ErrorLevel to get it
User avatar
boiler
Posts: 3113
Joined: 21 Dec 2014, 02:44

Re: is ErrorLevel a reserved word ?

30 Sep 2019, 18:25

Yes it is. It seems like you already know that it is.
gregster
Posts: 3277
Joined: 30 Sep 2013, 06:48

Re: is ErrorLevel a reserved word ?

30 Sep 2019, 18:30

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
User avatar
boiler
Posts: 3113
Joined: 21 Dec 2014, 02:44

Re: is ErrorLevel a reserved word ?

30 Sep 2019, 18:38

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. :D
User avatar
jeeswg
Posts: 6829
Joined: 19 Dec 2016, 01:58
Location: UK

Re: is ErrorLevel a reserved word ?

30 Sep 2019, 19:20

- 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.)
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
User avatar
boiler
Posts: 3113
Joined: 21 Dec 2014, 02:44

Re: is ErrorLevel a reserved word ?

30 Sep 2019, 19:41

jeeswg wrote:
30 Sep 2019, 19:20
- 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.
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.
User avatar
jeeswg
Posts: 6829
Joined: 19 Dec 2016, 01:58
Location: UK

Re: is ErrorLevel a reserved word ?

30 Sep 2019, 21:04

- 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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6829
Joined: 19 Dec 2016, 01:58
Location: UK

Re: is ErrorLevel a reserved word ?

30 Sep 2019, 22:56

Run this two-line script on AHK v1, and it lists A_Args and ErrorLevel:

Code: Select all

ListVars
MsgBox

;AHK v1:
;0, A_Args
;ErrorLevel

;AHK v2:
;A_Args
;Array, Class, Map, Object
;ErrorLevel
Here's a script to test if variables are writable:

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
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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: colt, eblanc, Google [Bot] and 62 guests