Oh my... I'm amazed the parser allows { as the first character in a line!
  • Who told you that you have to put every command between braces { } ? like

    { msg $nick $read(help.txt,n,1) }
    { msg $nick $read(help.txt,n,2) }

    The way to use if-then-else is like this:

    if (condition) {
    commands
    }
    elseif (another condition) {
    other commands
    }
    else {
    commands to do when no conditions have been met
    }

    And of course the if-then-else can be nested in other if then else constructs.

    You see how each condition starts with an opening brace { and ends that part of the code with a closing brace } ?

    Note that the else part isn't mandatory, if you don't have default commands, then you just leave it, instead of what some people do, which is totally obsolete: else { halt }


  • Note that braces are only needed to group multiple commands together.

    In the case of single commands, you don't need them, but you can use them. Always use either brackets ( ), or braces { }, or preferably both of them together ( ) { }, unless if you really know what you are doing.

    Example:

    Code:
    alias myalias {
    [color:red]  [/color] 
      if ($1 == !test) echo -a only brackets 
    [color:red]  [/color] 
      elseif $1 == !help { echo -a only braces }
    [color:red]  [/color] 
      elseif ($1 == !add) { echo -a both brackets and braces }
    [color:red]  [/color] 
      elseif $1 == !info {
    [color:red]  [/color] 
        echo -a first command
        echo -a second command
        echo -a third command
    [color:red]  [/color] 
      }
    
      else { echo -a Unknown command: $1 }
    
    }


  • The if, elseif, else construct has as benefit that if one condition matches, mirc will discard the following "elseifs" and "else" and goes to the end of the elseif/else conditions. This speeds up processing, as otherwise mIRC would go through each of those "if" lines to look if $1 matches, but that is completely obsolete, since it already matched exclusively.

    For example, in that alias I just provided, if you do: /myalias !test, mirc will do the following:

    1. it matches: if ($1 == !test)
    2. it performs the commands that go with that match: echo -a only brackets
    3. it sees that the rest of the if conditions are elseif's and an else, so the alias is finished.


    In some cases, it's needed to do multiple if's without making mIRC stop the script after having 1 match.

    Example:
    Code:
    alias alphabet {
    [color:red]  [/color] 
      if (*a* iswm $1) { echo -a found an "a" }
      if (*b* iswm $1) { echo -a found a "b" }
      ...
      if (*z* iswm $1) { echo -a found a "z" }
    [color:red]  [/color] 
    }
    
    


    Now if we do: /alphabet azerty

    What does mIRC do?

    1. it matches: if (*a* iswm $1)
    2. it performs the command associated with the match: echo -a found an "a"
    3. it matches: if (*e* iswm $1)
    4. it performs the command associated with the match: echo -a found an "e"
    ...

    In this case, we don't want to use elseif's, because after finding 1 match, mirc would skip all the elseif's and else, while we want to actually check each condition.
  • The examples provided are solely for educational purposes, and to get a point accross.

  • I didn't look at the rest, because I would have ended up rewriting your whole script. There is a lot of room to improve ricky, good luck!

Greeits

Last edited by FiberOPtics; 16/01/05 10:26 AM.

Gone.