A_ variables

Discuss the future of the AutoHotkey language
Helgef
Posts: 2990
Joined: 17 Jul 2016, 01:02
Contact:

Re: A_ variables

28 Feb 2018, 04:28

you get the inevitable question, should *all* 'A_' variables be removed

I'm definitely leaning in this direction. I think it would probably be ok to leave some true constants, such as A_AhkVersion, A_PtrSize and what else there might be. Note, for many of the BIV's, there is not just simple function substitution, eg, the hotkey BIVs, it needs restructuring the hotkey concept. Ofc, it is not going to happen :lol:.
- A_MsgBoxResult / A_InputBoxResult for AHK v1/v2.

It is not a good idea imo. (Surprised?)
ErrorLevel is positional

A_XXXResult will have the same limitiation, as will GetError(FuncName). Further A_XXXResult will either increase thread overhead or cause the same inconsitencies with interruptions as, eg, A_ThisHotkey. The solution is to store errorlevel in a variable when needed, so ofc, errorlevel shouldn't be used in v2 (for inputbox). The function(s) should return all that is needed. For example, something like this,

Code: [Select all] [Download] GeSHi © Codebox Plus

[text, errorlevel] := inputbox(...)
; or
errorlevel := inputbox(textOut, ...)

where errorLevel symbolises the content which is currently stored in the variable errorlevel when inputBox() returns.

As a side note, I'd prefer A_InputBoxResult (or another name) over errorlevel, but as indicated above, it would just be a bit less worse.

Cheers.

Edit: to be clear, my use if the word should indicates my preference, not my demand.
User avatar
jeeswg
Posts: 4506
Joined: 19 Dec 2016, 01:58
Location: UK

Re: A_ variables

28 Feb 2018, 17:04

- I suppose my best solution is to do one-liners every time I use ErrorLevel, to make it clear what function it corresponded to: Func(Arg1, Arg2), vError := ErrorLevel.
- Although this has to be done every time I use InputBox, hence why A_InputBoxResult seems sensible.
- Where possible, I remove ErrorLevel and use the function's return value instead.
- Are there problems re. thread-specific values for A_ variables at present? I did consider that.
- For custom functions, you set settings via super-global variables, not functions, right? A_ variables are greA_t.

- It's classic how when you move to functions, all the obvious things, that were impossible before, start becoming apparent. I'm seeing now how much better my scripts would have been had functions become the norm back when Poly started that commands as functions library. Using function output values directly, lessening the frequency of ErrorLevel use, one-liners, no in/contains limitations, more efficient code. On the flip side, those functions might have constrained development, we got StrReplace and the removal of subcommands, for example, versus clones of the commands.
sttrebo
Posts: 58
Joined: 27 Jan 2014, 12:31

Re: A_ variables

28 Feb 2018, 17:37

not sure if this has been requeted or not, if it has my apologies. any chance of having some user specified variables, A_Userxx, etc. Something that we could specify and then call from any script? this would give us the opportunity to read variable contents in different scripts without needing to use ini's or 'onmessage' statements.

if you've already dealt with this, please ignore this post.

thanks
Helgef
Posts: 2990
Joined: 17 Jul 2016, 01:02
Contact:

Re: A_ variables

01 Mar 2018, 02:53

Are there problems re. thread-specific values for A_ variables at present?

I mentioned A_ThisHotkey, the problem is that it is not thread specific, as documented.

Cheers.
User avatar
jeeswg
Posts: 4506
Joined: 19 Dec 2016, 01:58
Location: UK

Re: A_ variables

02 Mar 2018, 06:13

@Helgef: Re. these, rather than creating separate 'Play' commands, I had been thinking of something like Noesis's suggestion below, and/or to add further A_ variables. Since I never use the 'Delay' commands, I hadn't thought about this problem too much.
SetKeyDelay - A_KeyDelay/A_KeyDelayPlay/A_KeyDuration/A_KeyDurationPlay
SetMouseDelay - A_MouseDelay/A_MouseDelayPlay
Remove or alter the line "SendMode Input ; Recommended for new scripts due to its superior speed and reliability" - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=13&t=44974&p=203648#p203648
Noesis wrote:I tend to think that a better solution to this would be a change to SetKeyDelay so the options for the last parameter could be Play|Input

@sttrebo: That sounds like something that would require a change to the AutoHotkey source code, or a file that is always included. The best solution seems to be, in each script where you want a special variable, to have a function called XXX_MyFunc (or MyFunc), and a script called XXX.ahk (or MyFunc.ahk) that gets auto-included, that uses a super-global variable. That would work if the variable contents never change, otherwise you would need some way of communicating between scripts.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 3 guests