and vs if if Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mattkey
Posts: 8
Joined: 27 Aug 2018, 13:59

and vs if if

21 Sep 2018, 13:59

Hi!

This works:

Code: Select all

if master_volume = 0
{
    if master_mute = Off
    {
        SoundSet, -2, , mute
    }
}
and this does not work:

Code: Select all

if master_volume = 0 and master_mute = Off
{
    SoundSet, -2, , mute
}
Why?
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: and vs if if

21 Sep 2018, 14:03

Logical And can only be used in expressions. To use expressions in an if-statement, you need to use parentheses:
https://autohotkey.com/docs/commands/IfExpression.htm

Thus, try

Code: Select all

if (master_volume = 0 and master_mute = "Off")
mattkey
Posts: 8
Joined: 27 Aug 2018, 13:59

Re: and vs if if

21 Sep 2018, 14:13

Thank you!

I tried parentheses but without " ".

This did not work too

Code: Select all

if (master_volume = 0 and master_mute = Off)
Your solution works

Code: Select all

if (master_volume = 0 and master_mute = "Off")
In this script (few lines further) I use this and it works.

Code: Select all

if master_mute = On
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: and vs if if  Topic is solved

21 Sep 2018, 14:24

Again, the parentheses make it here (if-statement) an expression. Hence, literal strings then need to be enclosed in quotation marks, like always in expressions...
if (master_mute = "On") is equivalent to if master_mute = On

You need to distinguish between if-expression-style: https://autohotkey.com/docs/commands/IfExpression.htm
and if-traditional-style: https://autohotkey.com/docs/commands/IfEqual.htm
These are two different syntaxes.
mattkey
Posts: 8
Joined: 27 Aug 2018, 13:59

Re: and vs if if

21 Sep 2018, 15:27

As you noticed for sure I didn't study documentation very much...

Thank you! My problem is solved!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750, Rohwedder and 341 guests