Your code works because you apparently never leave that channel window. $active literally means "whichever window I currently have as the active window, whatever it happens to be." $comchan($nick,1) means "the first common channel I share with $nick"; however, there might be more than one common channel between you and $nick. That would require that you set up a loop index variable and loop through $comchan($nick,%i) until it becomes undefined.

The reason you need this is that you are looking to catch private messages directly to you (or your script) which is what the :?: part means. This also means that there will be no #channel associated with that event, so you cannot use $chan. In order to find the channels they share with you, you must use $comchan($nick,%i) as described below. This is a very simple task, one that you will use repeatedly throughout your scripting career.

Below you will find just the snippet of code, completely commented, that you will use (usually without such comments) to perform $comchan() type tasks, such as in on QUIT or on NICK or on *:TEXT/ACTION/NOTICE:*:?: events. It, or at least its idea, may be inserted anywhere that you need this kind of code.
Code:

  ;
  ;  Set up the loop index to start with the first common channel (if any).
  ;
  var %i = 1
  ;
  ;  Assume we have 3 common channels with this nick. Once %i is incremented to 4, then $comchan($nick,4) will 
  ;  fail the conditional test and we will drop out of the loop. If someone who is not on any channels with us 
  ;  triggers this remote, then $comchan($nick,1) will fail and we won't even process the loop at all.
  ;
  ;  $comchan($nick,1000) would return $null since we cannot possibly be on that many channels with them; by the
  ;  same token, if we share only 3 channels with them, then $comchan($nick,4) will also return $null and drop us
  ;  out of the loop.
  ;
  ;  $null == 0 == $false ... all three of those values will fail a conditional test. We'll look for $null in this 
  ;  instance.
  ;
  while ($comchan($nick,%i)) {
    ;
    ;  Here is where you will put the commands now that you have a channel to work with. If you have no further 
    ;  IF conditions inside this portion of the code, you can use $ifmatch throughout as the equivalent of $chan.
    ;  $ifmatch holds whatever the matching last condition was; in this case, it holds what is in the while condition
    ;  that matched - $comchan($nick,%i) - without having to resolve it again. If you have further IF-ELSEIF-ELSE 
    ;  tests to run, then you can set up a temporary local variable (such as %chan) to hold the name of the current
    ;  channel.
    ;
    ;  var %chan = $ifmatch
    ;
    ;  Do any commands you wish here.
    ;
    msg $ifmatch Host test 1 is successful.
    ;
    ;  Once you are finished with this common channel for $nick, increment %i to move to the next common channel
    ;  next time through the looping while condition.
    ;
    inc %i
  }

Your code uses the prefix ^ which is used in conjunction with the haltdef command to halt the default text. By itself, it does nothing (except in certain specific cases which do not currently apply to you); you can leave that part off. So, for a more complete example, using yours as the guide and omitting the comments, here is what your code should look like to respond to a /msg MDA test1 and posting the resulting msg in each common channel you share with $nick.
Code:

on *:TEXT:test1:?:{
  var % i = 1
  while ($comchan($nick,%i)) {
    msg $ifmatch Host test 1 is successful.
    inc %i
  }
}

If you only wanted this remote to react for a single, specific channel and only if you both are on that channel as well, then you can hard-code in the channel name, like this:
Code:

on *:TEXT:test1:?:{
  if (($me ison #MDAsChannel) && ($nick ison #MDAsChannel)) {
    msg #MDAsChannel Host test 1 is successful.
  }
}

If you wish to omit the check to see if they are on the channel, use this:
Code:

on *:TEXT:test1:?:{
  if ($me ison #MDAsChannel) {
    msg #MDAsChannel Host test 1 is successful.
  }
}

If you wish to omit the check to see if you are both on the channel because, perhaps because the channel accepts messages from nicks that are not on the channel (-n channel mode on most IRCds), just use the msg #MDAsChannel command without the IF and its conditions.
Code:

on *:TEXT:test1:?:{
  msg #MDAsChannel Host test 1 is successful.
}

I hope that this has explained how to use $comchan() to your satisfaction. By reading /help $comchan while keeping this in front of you, you should be able to grasp exactly how it works now.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C