| View previous topic :: View next topic |
| Author |
Message |
swankinrosco
Joined: 18 Jun 2008 Posts: 6
|
Posted: Wed Jun 18, 2008 10:11 pm Post subject: If / Else Question |
|
|
Has anyone accomplished a script that has a keystroke command with an embedded if:else to determine output?
EG:
a::
if (variable = 1) {
Send Hello
variable = 2
return
}
if (variable = 2) {
Send Goodbye
variable = 3
return
}
return
I'm trying to accomplish something like this but having little luck
[ Moderator!: Moved from Scripts and Functions ]
[Title edited. Please write descriptive titles for your topics. ~jaco0646] |
|
| Back to top |
|
 |
Elesar
Joined: 28 Jun 2007 Posts: 98
|
Posted: Wed Jun 18, 2008 11:48 pm Post subject: |
|
|
First, wrong section. There is a Help section in the forum for a reason.
Second, Please use the code tags when posting code. This will make the code much easier to read.
Third, you may be looking for something like this:
| Code: | #SingleInstance Force
Test := 0
!a::
If Test = 0
{
MsgBox, Hello
Test := 1
}
Else
{
If Test = 1
{
MsgBox, Goodbye
Test := 0
}
}
Return |
That could probably be done much more efficiently by someone with more time / experience that I have, but that works. |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Jun 19, 2008 12:52 am Post subject: |
|
|
one-uping elesar
| Code: | a::
Var:=!Var ; Flips var from 0 to 1 and viceversa
If Var ; Var=1
Send Hi
Else ; Var=0
Send Bye
Return |
my two cents on what the guy wanted
| Code: | a::
; Spells out hello when 'a' is pressed 5 times
If Var=0
Send h
Else If Var=1
Send e
Else If (Var=3) || (Var=4)
Send l
Else If Var=5
Send o
Var++ ; Adds 1 to var
Return |
next time post in the right section please |
|
| Back to top |
|
 |
Wouther
Joined: 01 May 2007 Posts: 79 Location: The Netherlands
|
Posted: Thu Jun 19, 2008 10:07 am Post subject: |
|
|
It can be even shorter, using the ternary operator!
| Code: | Test := 0
!a::
Send, % (Test = 0) ? "Hello" : "Goodbye"
Test := !Test
Return |
_________________ Printing css/html-formatted text |
|
| Back to top |
|
 |
Elesar
Joined: 28 Jun 2007 Posts: 98
|
Posted: Thu Jun 19, 2008 1:39 pm Post subject: |
|
|
Thats the great thing about these forums, you'll get several possible answers to your question (If is it feasible).
I have learned something new too!  |
|
| Back to top |
|
 |
|