$activecid gives the cid of the currently active window.

You could use
Code:
scid $activecid
before executing the commands to that active connection

e.g.
Code:
 
on 1:dialog:test:sclick:11: {
  echo -s $($active,0) : $active
  echo -s $($activecid,0) : $activecid
  echo -s $($cid,0) : $cid


  scid $activecid 
  echo -a $line($active,$line($active,0))
}