#if 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

#if

25 Nov 2021, 08:57

Trying to use #if in a short script, which should toggle it on/off when pressing / key

Code: Select all

#if (gameon = "True")
msgbox, x %gameon%

#if


\::
{
if (gameon = "True")
{
gameon := False
}
else
{
gameon := True
}
return
}
Not sure what's wrong O.O
User avatar
boiler
Posts: 17390
Joined: 21 Dec 2014, 02:44

Re: #if

25 Nov 2021, 09:25

Putting the #If before regular code and turning it off before the hotkey definition appears is not correct syntax (well, it's not incorrect -- the point is that it actually does nothing). Do not put the bare #If before the hotkey definition if you want it to apply to that hotkey. It will have no effect on your MsgBox statement at the top. It does not make regular code conditional or cause it to be triggered by some event.

Also, by making the hotkey conditional, the logic of the code within your hotkey won't work because it will only be active for one state of the variable, so it won't be able to toggle.
DarkSider
Posts: 50
Joined: 29 May 2019, 11:06

Re: #if

25 Nov 2021, 09:29

Well it's pretty hard for me to follow what you're trying to explain, You're telling me what not to do, can you tell me what i should do ?
User avatar
boiler
Posts: 17390
Joined: 21 Dec 2014, 02:44

Re: #if  Topic is solved

25 Nov 2021, 09:35

Well, it's pretty hard for me to tell you how to do it since you haven't explained when you want the MsgBox to appear, and making the \ key a toggle for the variable gameon does not require #If. It would only be necessary to make another hotkey active or not relative to the state of gameon. For example, the Tab key below is active depending on whether you've toggled gameon or not using the \ key:

Code: Select all

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

\::gameon := !gameon
DarkSider
Posts: 50
Joined: 29 May 2019, 11:06

Re: #if

25 Nov 2021, 09:39

Well that looks so simple, thanks.

So basicly, the part between #if's it's not executed by the \ key, it's just activated/dezactivated by it. And while active, it will affect the code within.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: moltenchees and 167 guests