mIRC Homepage
Posted By: pball Stop timer from evaluating $1- - 01/04/11 03:12 PM
I made a script to add a delay between lines when pasting multiple lines. There is one problem and it's that anything pasted gets evaluated.

I found something weird when trying to $eval() to stop that.

//echo -a $eval($version,0)
$version
//.timer 1 1 echo -a $eval($version,0)
7.19

The timer evaluates $version even though $eval(,0) was used. How can I get the timer to not evaluate $1- and would this be a bug?
Posted By: DJ_Sol Re: Stop timer from evaluating $1- - 01/04/11 04:19 PM
Don't know if it's a bug, but try:

.timer 1 1 echo -a $!eval($version,0)
Posted By: Horstl Re: Stop timer from evaluating $1- - 01/04/11 05:09 PM
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.
Posted By: pball Re: Stop timer from evaluating $1- - 01/04/11 06:18 PM
DJ_Sol:
That'd work except I'm using $1- so that will be null when the timer goes off and it evals it then.

Horstl:
Using the play command would mean I'd have to write stuff to file and stuff which I'm just gonna stay away from for something like this.

I'll check out those aliases though.
Posted By: jaytea Re: Stop timer from evaluating $1- - 01/04/11 08:22 PM
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.
© mIRC Discussion Forums