AutoHotkey Community

It is currently May 27th, 2012, 4:19 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: February 21st, 2010, 5:05 pm 
Offline

Joined: November 12th, 2009, 4:39 pm
Posts: 17
back with another basic question that google couldn't help me with. Is there anything like a switch/case syntax (?) in AHK?

I think there was in AutoIt... I currently use a load of "If"s but it's pretty ugly.

Second question: What do I do if I need two conditions to apply in one "if"? I need something like:

if (a > 2 and b < 5)
xxx

Thanks, again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2010, 5:22 pm 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
you know that you are aloud to try code BEFORE asking if it will work ;).
Code:
a=6
b=4
if (a > 2 and b < 5) ; you may use &, &&, and, |, || , or
{
    msgbox
    run, notepad
}

and no, no case-break in AHK.

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Last edited by tidbit on February 21st, 2010, 5:24 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2010, 5:23 pm 
Quote:
Is there anything like a switch/case syntax (?) in AHK?

Not yet, but you could use the ternary operator:
Code:
x := 10
test :=      x=1   ?   "one"
      :      x=2   ?   "two"
      :      x=3   ?   "three"
      :      x=4   ?   "four"
      :      "other"
MsgBox, %test%


Quote:
What do I do if I need two conditions to apply in one "if"?

Your syntax is correct - you could add brackets if you want multiple lines:
Code:
a := 3, b := 3
if (a > 2 and b < 5) {
   MsgBox, 1
   MsgBox, 2
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2010, 5:40 pm 
Offline

Joined: November 12th, 2009, 4:39 pm
Posts: 17
tidbit wrote:
you know that you are aloud to try code BEFORE asking if it will work ;).
Code:
a=6
b=4
if (a > 2 and b < 5) ; you may use &, &&, and, |, || , or
{
    msgbox
    run, notepad
}

and no, no case-break in AHK.


I DID try that. I also looked at some existing scripts but couldn't find anything. Why is my script not working?

I had tried if (a > 3 and b = blue)

so I used a string rather than a number. Is that not allowed? I tried putting it in parenthesis but that doesn't seem to work either.

Thank you for your patience, I promise I am trying but I'm doing everything wrong I possibly could...

Code:
if (Color = "Blue" or Color = "White")
{
    MsgBox The color is one of the allowed values.
    ExitApp
}


This exact thing is in the documentation so what am I doing wrong?

this is what I'm playing around with:
Code:
MButton UP::
colour = "red"
players = 2

if (colour = "red")

msgbox, Red

Else
msgbox, Not red

Return


Last edited by hypertyper on February 21st, 2010, 5:48 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2010, 5:42 pm 
Code:
I had tried if (a > 3 and b = "blue")

so I used a string rather than a number.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2010, 5:45 pm 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
if ()
...
the () make it an expression.
strings inside expressions need to be quoted.
Code:
if (blah == "blue")
if (blah = "blue")
if (car=12 && blah == "blue")
if (car==12 & blah = "blue")

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2010, 5:53 pm 
Offline

Joined: November 12th, 2009, 4:39 pm
Posts: 17
Code:
MButton UP::
colour = "red"
players = 2

if (colour = "red")

msgbox, Red

Else
msgbox, Not red

Return


It's telling me it's not red. I'm going crazy.

lol

so when you define it you need to leave the parenthesis out and in the if bracket you need to have it in. You're not making my life easy here :lol:

so this works:

Code:
MButton UP::
colour = red
players = 2

if (colour = "red")

msgbox, Red

Else
msgbox, Not red

Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2010, 5:56 pm 
Code:
colour := "red" ; or colour = red
players = 2

if (colour = "red") ; no blank line
msgbox, Red

Else
msgbox, Not red

Return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2010, 6:02 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Or this would have worked
Code:
MButton UP::
colour := "red"
players = 2

if (colour = "red")

msgbox, Red

Else
msgbox, Not red

Return

edit
answer4u beat me to it :)

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Mickers, rbrtryn and 73 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group