|
rtatum Novice
Joined: 19 Sep 2004 Posts: 45 Location: Houston
|
Posted: Thu Oct 28, 2004 8:58 pm
Help with an alias for modifying a variable, et cetera |
The channel OOC sometimes gets a bit spammy, so I like to turn it off... I wrote a simple alias to do this, but I need help fitting something into it
#IF ("%1"="off") {
ooc=0
#ECHO OOC turned off.
}
#IF ("%1"="on") {
ooc=1
#ECHO OOC turned on.
}
#IF ((@ooc="0") & ("%1"!={on|off}) & (%numwords(%-1)>1) {#ECHO OOC is off, cannot speak.}
That is my current alias, ooc... so I type ooc off, and it sets the ooc variable to 0, I type ooc on, it sets it to 1, and the third if statement says OOC is off, cannot speak if OOC is set to 0, and there's more than one word, and that one word isn't the on or off command... The third if statement might not be functioning properly, but also what I want to add in is if OOC is set to 1, and the arguement isn't on or off, then it just sends the command ~ooc %-1, so I talk on the channel... |
|
|
|
misterbalrog Apprentice
Joined: 26 Oct 2004 Posts: 108
|
Posted: Thu Oct 28, 2004 9:48 pm |
well, if ooc = 1, the IF statement you have will fail, and you will have natural access to it in the current IF-statement: #IF (expr) {true} {false}, so you should probably just add ~ooc %-1 there...
You're expressing yourself in a funny manner for me, so I might of missunderstood what you're trying to do, but as I see it, that should do it. |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Thu Oct 28, 2004 9:57 pm |
#IF ((@ooc="0") & ("%1"!="on" OR "%1"!="off" ) & (%numwords(%-1)>1) {#ECHO OOC is off, cannot speak.} {~ooc "%-1"}
|
|
|
|
rtatum Novice
Joined: 19 Sep 2004 Posts: 45 Location: Houston
|
Posted: Thu Oct 28, 2004 10:26 pm |
#IF ("%1"="off") {
ooc=0
#ECHO OOC turned off.
}
#IF ("%1"="on") {
ooc=1
#ECHO OOC turned on.
}
#IF ((@ooc="0") & ("%1"!="on" OR "%1"!="off" ) & (%numwords( %-1)>1)) {#ECHO OOC is off, cannot speak.} {~ooc "%-1"}
Now if I type ooc on, or ooc off, it switches the variable correctly, but now it ALSO sends ooc on or ooc off to the mud... |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Thu Oct 28, 2004 10:53 pm |
IF (@ooc=0 AND (%lower("%1")!="on" OR %lower("%1"!="off")) AND %numwords("%-1")>0) {
#ECHCO Ooc is off
} {
~ooc "%-1"
} |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Thu Oct 28, 2004 10:56 pm |
Personally I would rewrite the entire logic. It is erronious to check only %1 for "off" and "on" without checking %numparam anyway. For example "ooc off to the races" would incorrectly turn the ooc channel off. Let's start by checking the parameter count, then check the specific words, and finally process of elimination will have given us the other results.
#ALIAS ooc {
#IF (%numparam=1) {
#IF ("%1"="off") {
ooc=0
#ECHO OOC turned off.
} {
#IF ("%1"="on") {
ooc=1
#ECHO OOC turned on.
} {
#IF (@ooc) {~ooc %1} {#ECHO OOC is off, cannot speak.}
}
}
} {
#IF (@ooc) {~ooc %-1} {#ECHO OOC is off, cannot speak.}
}
}
While this is not actually shorter it covers the logical case you forgot about. This makes use of what is commonly called an if-else chain to check the logic. This allows the logic to rapidly narrow, and is generally used for speed. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
|
|