Multiple commands under an 'if' statement Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
roysubs
Posts: 257
Joined: 29 Sep 2018, 16:37

Multiple commands under an 'if' statement

10 Apr 2020, 05:01

Some questions on the Python-like indent option with Autohotkey.

Take this example:

Code: Select all

MsgBox, 4,, Would you like to continue? (press Yes or No)
IfMsgBox Yes
    MsgBox You pressed Yes.
To do more under the 'IfMsgBox Yes' line, I have to do:

Code: Select all

MsgBox, 4,, Would you like to continue? (press Yes or No)
IfMsgBox Yes
{
    MsgBox You pressed Yes.
    x := 123
}
Or is there an alternative, can I do more under the 'IfMsgBox Yes' line without the { } ?

Code: Select all

MsgBox, 4,, Would you like to continue? (press Yes or No)
IfMsgBox Yes
    MsgBox You pressed Yes. <some divider that says next command> x := 123 <divider> y := 234
In PowerShell for example, they use ";" to have multiple commands on one line:

Code: Select all

$x = 0 ; $y = 1 ; $z = 2
User avatar
Scr1pter
Posts: 1200
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Multiple commands under an 'if' statement

10 Apr 2020, 05:20

I believe the answer is no.

However, you could add just a function under
IfMsgBoxYes.

Inside of your function you place your code lines.

Cheers!
Please use [code][/code] when posting code!
Keyboard: Logitech G15 FE - Mice: Logitech G9 FE, G502 FE, G602, Jelly Comb Touchpad - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.32.00
just me
Posts: 7224
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Multiple commands under an 'if' statement  Topic is solved

10 Apr 2020, 05:27

Comma (multi-statement), but in general it can be used only for expressions/functions, not for commands.
roysubs
Posts: 257
Joined: 29 Sep 2018, 16:37

Re: Multiple commands under an 'if' statement

10 Apr 2020, 06:30

Both really useful, thanks for the clarifications.

Return to “Ask For Help”

Who is online

Users browsing this forum: TAC109 and 42 guests