Originally Posted By: Horstl
I'd rather not use $eval (what about a space-separated string, or a line containing brackets).

I suggest to use either one of the "safe"- (i.e.: non-eval) aliases you can find on these boards, for example:
Code:
alias safe2 bset -tc &a 1 $1 | return $!regsubex(safe, $bvar(&a,1-) ,/(\d+)(?: |$)/g,$chr(\1))


...or to not use any timer at all but the /play command.


since this alias is so common, might i suggest a new and straight forward method? since mIRC 7's release, we have many new characters to play with and since the line length limit of 4,150 chars is considerably less than the number of Unicode code points available with $chr(), a simple character replacement is no longer unreasonable.

Code:
alias safe {
  return $!desafe(( $+ $replace($1, $chr(32), $chr(57344), $chr(40), $chr(57345), $chr(41), $chr(57346)) $+ )) 

}

alias desafe {
  return $replace($mid($1, 2, -1), $chr(57344), $chr(32), $chr(57345), $chr(40), $chr(57346), $chr(41))
}


used in much the same way as existing methods, //timer 1 3 echo -a $safe($1-) and such.

all spaces and parentheses are replaced by the first 3 characters of the BMP's Private Use Area (U+E000 - U+F8FF) - a range of Unicode code points that are hitherto unassigned - and commas as well as leading identifiers within $1- are handled by enclosing the encoded string in '(' and ')', rendering them plaintext.

the replacements + padding makes the string safe without multiplying its length as in $encode( , m) or the above $bvar() method.

and just in case it is actually too bold to assume that the absence of certain characters can never be predicted, and we wanted a fully capable alias, we can use this instead:

Code:
alias safe {
  var %chr1, %chr2, %chr3, %chrs

  if ($chr(32) isin $1) {
    while ($chr($rand(256, 65535)) isin $1) /
    %chr1 = $v1
  }

  if ($chr(40) isin $1) {
    while ($chr($rand(256, 65535)) isin $1) /
    %chr2 = $v1
  }

  if ($chr(41) isin $1) {
    while ($chr($rand(256, 65535)) isin $1) /
    %chr3 = $v1
  }

  %chrs = , %chr1 , %chr2 , %chr3

  return $!desafe(( $+ $replace($1, $chr(32), %chr1, $chr(40), %chr2, $chr(41), %chr3) ) %chrs ) 

}

alias desafe {
  return $replace($mid($1, 2, -1), $2, $chr(32), $3, $chr(40), $4, $chr(41))
}


those loops are guaranteed to terminate, and quickly too, due to mIRC's line length limit being almost 20 times less than the number of characters in those $rand ranges. it still isn't perfectly optimal with regards to the length of the output string (could still add a few more $+s, shorten the name 'desafe', etc.) but it's better than existing methods.


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde