This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Multiple if $nicks? [SOLVED]

Help for those learning Tcl or writing their own scripts.
Post Reply
D
DJCharlie
Voice
Posts: 37
Joined: Wed May 06, 2009 10:45 am
Contact:

Multiple if $nicks? [SOLVED]

Post by DJCharlie »

Ok, say I've got this bit of code:

Code: Select all

  if {$nick == "DJCharlie"} {
  ...rest of proc goes here...
  }
What I'd like, is to check if the nick is DJCharlie OR another authorized nick. Is that possible? If so, how?

Thanks in advance!
Last edited by DJCharlie on Fri Jun 18, 2010 3:20 pm, edited 1 time in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

To use the logical OR in a conditional, do something like this:

Code: Select all

...
if {conditional1 || conditional2} {
...
Where conditional1 would be one conditional such as $nick == "DJCharlie".

In the case you'd like to test one variable against multiple values, this could be optimized using the switch command:

Code: Select all

...
switch $nick {
  "DJCharlie" -
  "NML_375" -
  "SomeOtherDude" {
    ...
  }
}
..
In this case, the - means "use the next match", which allows us to stack an infinite number of cases to use the same code.
NML_375
D
DJCharlie
Voice
Posts: 37
Joined: Wed May 06, 2009 10:45 am
Contact:

Post by DJCharlie »

That fixed it, thanks!
Post Reply