can you include #if inside #ifwinactive ? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DarkSider
Posts: 50
Joined: 29 May 2019, 11:06

can you include #if inside #ifwinactive ?

25 Nov 2021, 12:17

I'm trying to include an #if inside this #ifwinactive, and doesn't seem to work, the script works outside that active window. Not sure if it's supposed to work or just my syntax it's bad somewhere .

Code: Select all

#IfWinActive They Are Billions

#If (gameon = True)
{
Tab::MsgBox "gameone is true"
}

#if

#IfWInactive

\::gameon := !gameon
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: can you include #if inside #ifwinactive ?  Topic is solved

25 Nov 2021, 12:34

No, you can't - not this way, at least. Only the last #If or #IfWin... above a hotkey counts. In your code above, #IfWinActive They Are Billions will be canceled out.

But you can combine the conditions like this, by using logical AND (&&) and the WinActive() function, because #If works with expressions:

Code: Select all

#If (gameon = True) && WinActive("They Are Billions")
	Tab::MsgBox "gameone is true"
#If
(btw, directives don't need brackets)
DarkSider
Posts: 50
Joined: 29 May 2019, 11:06

Re: can you include #if inside #ifwinactive ?

25 Nov 2021, 12:42

Oh cheers, i thought to use the && but i thought one would need an if to close and another ifwinactive, didn't know both will close with the same command.
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: can you include #if inside #ifwinactive ?

25 Nov 2021, 12:46

DarkSider wrote:
25 Nov 2021, 12:42
Oh cheers, i thought to use the && but i thought one would need an if to close and another ifwinactive, didn't know both will close with the same command.
Well, there is no both in this case, since we only have #If - and the function WinActive(), but no #IfWinActive directive, which are different things.
But yes, one #If is always enough to close a context-sensitive section.
DarkSider
Posts: 50
Joined: 29 May 2019, 11:06

Re: can you include #if inside #ifwinactive ?

25 Nov 2021, 12:55

Got ya, it was just stuck in my head that ifwinactive command must be the one and only way to check if the window is active, didn't think that winactive could also be a condition to use :D

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], moltenchees and 150 guests