(Script) Need Help with if statement

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
HudsonRyder
Posts: 1
Joined: 18 Jun 2018, 12:06

(Script) Need Help with if statement

18 Jun 2018, 12:16

Basically, I want to use an If statement but instead of writing the expression out I want the expression to be stored in a variable and I want to use that variable in the if statement.

Code: Select all

query := Comp = 1 or Comp = 2
if (query)
{
	MsgBox allowed
while (looping = on)
{
	Loop 
{
	BlockInput, On
	Send T
	Sleep 100
	Send /ad %Msg%
	Send {return}
	BlockInput, Off
	Sleep 10000
}
}
}
Whats happening with this code is that if Comp = 3 then I still get the msg box allowed and the loop starts.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: (Script) Need Help with if statement

18 Jun 2018, 13:00

It does not on my machine, I would like to help but it's working for as far as I can see.
User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: (Script) Need Help with if statement

18 Jun 2018, 13:54

Hi HudsonRyder,

There are numerous issues with your script:

(1) The indenting should be improved, i.e., the While statement should be at the same level as the MsgBox statement, with the code following it indented accordingly.

(2) The while (looping = on) statement doesn't make sense as is, for two reasons. First, the looping var is never assigned a value, but perhaps this is just a code snippet, not the full script, and that it is assigned a value elsewhere. Second, if it is assigned a value, I'm guessing that it is the literal on or off. If so, the statement should be while (looping = "on").

(3) Do you really need/want a Loop statement following the While statement? Since it is a forever Loop, I don't see its purpose inside the While loop. So, you could just have the statements in the Loop be statements in the While.

Taking all of that into account, the code would be this:

Code: Select all

query := Comp = 1 or Comp = 2
if (query)
{
  MsgBox allowed
  while (looping = "on")
  {
    BlockInput, On
    Send T
    Sleep 100
    Send /ad %Msg%
    Send {return}
    BlockInput, Off
    Sleep 10000
  }
}
Of course, for that code to make sense, the  looping var needs to be assigned values somewhere (presumably, "on" and "off"). Also, the Msg var needs to be assigned values. Btw, as DyaTactic noted, the query := Comp = 1 or Comp = 2 statement works as is. Regards, Joe
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: (Script) Need Help with if statement

18 Jun 2018, 14:48

HudsonRyder wrote:... Whats happening with this code is that if Comp = 3 then I still get the msg box allowed and the loop starts.
no, using ahk_l 1.1.29.01:

Code: Select all

comp := 3
query := Comp = 1 or Comp = 2
msgbox % query
if (query)
{
	MsgBox allowed
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo and 227 guests