A_ThisVariant
A_ThisVariant
if the same hotkey key can be triggered by multiple #if conditions, would be nice to have an easy way to know which variant triggered the hotkey
Re: A_ThisVariant
What value is it supposed to have?
Re: A_ThisVariant
to allow you to know which variant triggered the hotkey
pseudocode example
Code: Select all
Hotkey, If, MouseIsOverNotepad()
Hotkey, F1, F1_Func(), on
Hotkey, If, FirefoxIsActive()
Hotkey, F1, F1_Func(), on
F1_Func()
{
;currently need to loop through all #if conditions and re-test ourselves to determine which variant has triggered this func
if MouseIsOverNotepad()
msgbox mouseover variant
else if FirefoxIsActive()
msgbox winactive variant
}
Re: A_ThisVariant
@guest3456, why not use
I modified the example for v2 because v1 isn't getting any new features.
Code: Select all
HotIf MouseIsOverNotepad
Hotkey "F1", F1_Func.Bind("Notepad")
HotIf FirefoxIsActive
Hotkey "F1", F1_Func.Bind("Firefox")
F1_Func(ThisVariant) {
if ThisVariant = "Notepad"
msgbox "mouseover variant"
else if ThisVariant = "Firefox"
msgbox "winactive variant"
}
- WarlordAkamu67
- Posts: 231
- Joined: 21 Mar 2023, 06:52
Re: A_ThisVariant
There are a few ways to figure out which variant was pressed as with any code stuffs. The HotIf line as a string is one suggestion for the value, if the variable is made.
Code: Select all
HotIf MouseIsOverNotepad
Hotkey "F1", F1_Func() ; Says "MouseIsOverNotepad"
HotIf(FirefoxIsActive())
Hotkey "F1", F1_Func() ; Says "FirefoxIsActive()"
HotIf(FirefoxIsActive() && otherThings() || moreFunctions())
Hotkey "F1", F1_Func() ; Says "FirefoxIsActive() && otherThings() || moreFunctions()"
F1_Func() {
MsgBox(A_ThisVariant) ; Where the display is the string of the HotIf
}
Re: A_ThisVariant
@WarlordAkamu67
Suppose A_ThisVariant returned the string of the HotIf function call argument.
This case is simple, as A_ThisVariant would be the string "MouseIsOverNotepad"
However, we can bind arguments to functions:
What should the string be now? "MouseIsOverNotepad.Bind(1)" or "MouseIsOverNotepad(1)" or ignore the argument and return "MouseIsOverNotepad"?
We can also assign functions to variables:
Is A_ThisVariant now "MouseIsOverNotepad" or "f"?
Okay, suppose we said that only the *actual* function name should be returned ("MouseIsOverNotepad", not "f"). What should we do in the case of anonymous functions?
Would A_ThisVariant be "" or "(*) => MouseIsOverNotepad()"?
Then we have the case of #HotIf with multiple conditions, eg
but suppose that in another part of my code I used
These are equivalent, but should A_ThisVariant return different strings?
As you see this would get complex and convoluted. Just use BoundFuncs as I showed in my example...
Suppose A_ThisVariant returned the string of the HotIf function call argument.
Code: Select all
HotIf MouseIsOverNotepad
However, we can bind arguments to functions:
Code: Select all
HotIf MouseIsOverNotepad.Bind(1)
We can also assign functions to variables:
Code: Select all
f := MouseIsOverNotepad
HotIf f
Okay, suppose we said that only the *actual* function name should be returned ("MouseIsOverNotepad", not "f"). What should we do in the case of anonymous functions?
Code: Select all
HotIf (*) => MouseIsOverNotepad()
Then we have the case of #HotIf with multiple conditions, eg
Code: Select all
#HotIf FirefoxIsActive() && otherThings()
Code: Select all
#HotIf FirefoxIsActive() and otherThings()
As you see this would get complex and convoluted. Just use BoundFuncs as I showed in my example...
Re: A_ThisVariant
I mean "What value is the variable supposed to return?", not "What is the worth of this feature?"
For v1, which I will not be adding features to anyway, criteria is a combination of multiple parameters.
Only #HotIf has a string (it also has an anonymous function). HotIf only has a function object. A function such as HotIf only knows what parameters it was given, not the source code of the expression which provided the values.
If it returns strings, it must return the appropriate string for the current variant. A variant which was created under a && b cannot be referenced by setting the criteria to a and b. A case such as below would create two separate variants, though one would never execute unless the other was disabled.These are equivalent, but should A_ThisVariant return different strings?
Code: Select all
#HotIf a && b
x::MsgBox 1
#HotIf a and b
x::MsgBox 2
- WarlordAkamu67
- Posts: 231
- Joined: 21 Mar 2023, 06:52
Re: A_ThisVariant
I kind of pictured it in my head like trimming the error window code, so whatever that is displayed there. So I guess it would "MouseIsOverNotepad.Bind(1)" and "f"? I don't have any great examples of a use case, but that is what I think of for a potential value, if assigned.
Re: A_ThisVariant
#HotIf is a directive, and as such its parameter is literal source code. The directive creates an anonymous function and sets it as the current hotkey criterion. Since the script has no way to refer to this function directly, it also stores the expression source code for use with the HotIf function and to merge exact duplicates. #HotIf is allowed only in global scope, so two lines with an exactly identical expression would behave the same even if they weren't implicitly merged.
The HotIf function takes a function object. A unique function object may not directly correspond to literal source code, and even if it did, the same snippet of source code can have different interpretations depending on scope. Unlike #HotIf, HotIf can be used in local scope.
More importantly, functions receive only the values of their parameters. Attempting to self-introspect to determine the source code snippet corresponding to the parameter would be slow and error-prone. Error dialogs only show the line that called the function. A line can contain multiple calls to HotIf. The same source code can correspond to many different unique function objects, even if there's only one call to HotIf in the entire script.
The HotIf function takes a function object. A unique function object may not directly correspond to literal source code, and even if it did, the same snippet of source code can have different interpretations depending on scope. Unlike #HotIf, HotIf can be used in local scope.
More importantly, functions receive only the values of their parameters. Attempting to self-introspect to determine the source code snippet corresponding to the parameter would be slow and error-prone. Error dialogs only show the line that called the function. A line can contain multiple calls to HotIf. The same source code can correspond to many different unique function objects, even if there's only one call to HotIf in the entire script.
Re: A_ThisVariant
thanks. this should workDescolada wrote: ↑16 Feb 2024, 15:22@guest3456, why not useI modified the example for v2 because v1 isn't getting any new features.Code: Select all
HotIf MouseIsOverNotepad Hotkey "F1", F1_Func.Bind("Notepad") HotIf FirefoxIsActive Hotkey "F1", F1_Func.Bind("Firefox") F1_Func(ThisVariant) { if ThisVariant = "Notepad" msgbox "mouseover variant" else if ThisVariant = "Firefox" msgbox "winactive variant" }
ahh gotcha. not sure what the value of the variable should be, given the difficulties already mentioned. i'm fine using the .Bind method