When executing this code:
Switch
{
Case WinActive("window1"):
a := 1
Case WinActive("window2"):
a := 2
}
The case WinActive("window1") result always true and is always executed cause WinActive("window1") return value 0x0 wich is strangely considered True but is a 0 so must be considered false.
Insted the same code using If has no problems:
If WinActive("window1") {
a := 1
} Else If WinActive("window2") {
a := 2
}
I am using AutoHotkey v1.1.31.01 64 bit on Windows 10 64 bit.
Thanks for any Help!
Bug! Switch not work with Expressions!
-
- Posts: 10
- Joined: 21 Oct 2019, 13:26
Bug! Switch not work with Expressions!
Last edited by ShadowMaster85 on 25 Oct 2019, 14:58, edited 1 time in total.
Re: Bug Switch and WinActive
i havent looked into how Switch is supposed to work on v1 or how it's implemented, but it looks like a bug. the same example runs flawlessly on v2 fwiw, so maybe the problem is with expressions
u can force it into a bool with Case !!WinActive("window1"): or use switch true for the time being
u can force it into a bool with Case !!WinActive("window1"): or use switch true for the time being
-
- Posts: 10
- Joined: 21 Oct 2019, 13:26
Re: Bug Switch and WinActive
Using Switch True the case WinActive("window1") never trigger when is true:
Switch True
{
Case WinActive("window1"):
a := 1
Case WinActive("window2"):
a := 2
}
Using Switch without value and Case !! the code work:
Switch
{
Case !!WinActive("window1"):
a := 1
Case !!WinActive("window2"):
a := 2
}
But it's only a workaround, there is always a bug since the expression is not correctly evalutated (unlike If wich evalutate all this expressions correctly), using the switch normally the case WinActive("window1") result always true and is always executed cause WinActive("window1") return value 0x0 wich is strangely considered True but is a 0 so must be considered false.
When will be available a fix to this bug? Many thanks!
Switch True
{
Case WinActive("window1"):
a := 1
Case WinActive("window2"):
a := 2
}
Using Switch without value and Case !! the code work:
Switch
{
Case !!WinActive("window1"):
a := 1
Case !!WinActive("window2"):
a := 2
}
But it's only a workaround, there is always a bug since the expression is not correctly evalutated (unlike If wich evalutate all this expressions correctly), using the switch normally the case WinActive("window1") result always true and is always executed cause WinActive("window1") return value 0x0 wich is strangely considered True but is a 0 so must be considered false.
When will be available a fix to this bug? Many thanks!
-
- Posts: 10
- Joined: 21 Oct 2019, 13:26
Re: Bug Switch and WinActive
The same bug in these cases:
Switch
{
Case a:
msgbox ff
Default:
msgbox n
}
If value a := 0 or a := False the case a result always true and is always executed, but since the value is False or 0 it must not be executed.
Switch
{
Case a:
msgbox ff
Default:
msgbox n
}
If value a := 0 or a := False the case a result always true and is always executed, but since the value is False or 0 it must not be executed.
Re: Bug! Switch not work with Expressions!
This is an indirect product of this v1 quirk:
Case evaluates its expression and, if it is a string, returns a SYM_STRING value.
It will be fixed.
During expression evaluation, quoted strings (and the results of concatenating quoted strings) are identified as SYM_STRING, while (string) values of undetermined type are SYM_OPERAND. The latter includes numeric constants, return values from functions and the result of concatenating (if there are no quoted strings involved). SYM_STRING is always considered non-numeric, and therefore never considered zero; the only false value is "". For example:Note: In AutoHotkey v1, a quoted string (or the result of concatenating with a quoted string) is never considered numeric when used directly in an expression.
Source: Variables and Expressions - Definition & Usage | AutoHotkey
Code: Select all
if "0" && 1
MsgBox True!
It will be fixed.
It is probably never true (1). WinActive returns a window handle or zero as a hexadecimal string, not a boolean value. If WinActive("window1") = true is false.ShadowMaster85 wrote:Using Switch True the case WinActive("window1") never trigger when is true
If present, SwitchValue is evaluated once and compared to each case value until a match is found, and then that case is executed. Otherwise, the first case which evaluates to true (non-zero and non-empty) is executed.
-
- Posts: 10
- Joined: 21 Oct 2019, 13:26
Re: Bug! Switch not work with Expressions!
When using Switch without value:lexikos wrote:It is probably never true (1). WinActive returns a window handle or zero as a hexadecimal string, not a boolean value. If WinActive("window1") = true is false.ShadowMaster85 wrote:Using Switch True the case WinActive("window1") never trigger when is trueIf present, SwitchValue is evaluated once and compared to each case value until a match is found, and then that case is executed. Otherwise, the first case which evaluates to true (non-zero and non-empty) is executed.
Switch
{
Case WinActive("window1"):
msgbox a
}
The Case WinActive("window1") is always executed even if window1 is not active, but when i use the same condition with if: If WinActive("window1") it execute the code contained inside that if only if window1 is active.
Anyway this is always relative to the same bug?
Thanks for your help!
Re: Bug! Switch not work with Expressions!
I already explained that bug.
Your "switch true" example is unrelated, and is not a bug. It is how switch is supposed to work.
Your "switch true" example is unrelated, and is not a bug. It is how switch is supposed to work.
Re: Bug! Switch not work with Expressions!
Same bug for me too, I thought I was the one so far.
Last edited by gregster on 28 Nov 2019, 20:09, edited 1 time in total.
Reason: Spam removed.
Reason: Spam removed.
Who is online
Users browsing this forum: No registered users and 54 guests