mIRC Homepage
Posted By: LostShadow Input event questions. - 22/05/05 01:18 AM
Several input questions.

How would I get, in a $1-, to bring up spaces between words and , ! ?'s

For example,

Hello there !, would be, Hello there!

Secondly, how would I remove excessive of them chars.

Huh????? would be Huh?

Thirdly, now depending on the first and second code, there may not be need for a 3rd one.

A Hello there !!!, if the first code does not make it Hello there!!! and the second code does not make that one Hello there!, then yes, a third code to bring the two codes together.

And, in an input $1- string, how would I detect if one $N is before another $N?

For example, if the word 'Jackie' is before the word 'chan' in a $1- string,. I have a code that makes 'chan' 'channel' and was wondering if there was a way to have mirc detect if a certain word is before one, so I could use it in an if statement.

Thanks.
Posted By: DaveC Re: Input event questions. - 22/05/05 04:06 AM
Code:
on *:input:*:{
  if ($target && !ctrlenter && !$inpaste) {
    ;^ must have a taget window and not be in ctrlentered line or a paste
    ;
    tokenize 32 $1- | var %text = $1-
    ;^ store up $1- into something
    ;
    var %text = $replacex(%text, $chr(32) $+ !,!, $chr(32) $+ ?,?)
    ;^ part 1(join blah ! to blah!)
    ;
    while ((!! isin %text) || (?? isin %text)) { var %text = $replacex(%text, !!,!, ??,?) }
    ;^ part 2 (change blah!!!! to blah!)
    ;
    if ($1- != %text) {
      ;^ somethings changed so cancel this line and reinsert the line into the editbox
      ;
      haltdef | editbox $iif($target == Status Window,-ns,-n $target) %text
    }
  }
}


the 3rd part i didnt add becuase i cant quite be sure what you wanted.

if (*jackie*chan* iswm $1-) { echo -a JACKIE THEN CHAN in $!1- }
^ however that doesnt need them to be whole words it could be "heres macjackie and the chanters"

if ((* jackie * chan * iswm $+($chr(32),$1-,$chr(32))) || (* jackie chan * iswm $+($chr(32),$1-,$chr(32))) { echo -a JACKIE THEN CHAN in $!1- }
^ that well make it whole words, i dont know if its the best method but it works, spaces needed adding around the $1- incase jackie or chan were the first or last words, and there are two wildmatches the second incase jackie and chan are next to each other with no word between.
Posted By: Sigh Re: Input event questions. - 22/05/05 05:41 AM
Another way to get rid of the excess ! and ? while removing spaces in front of them is to use the substitution $regsub($1-,/ ?([?!])(?: ?\1)*/g,\1,%var)

Also Dave you missed a $ in !ctrlenter at the top. Might also want to check it's not a command (/* !iswm $1)
Posted By: DaveC Re: Input event questions. - 22/05/05 06:19 AM
much nicer the regex is i must say, as to the errors in my script, well that well teach me for writting it in the thread reply window smile
Posted By: tidy_trax Re: Input event questions. - 22/05/05 03:37 PM
Code:
on *:input:#:{
  if (!$istok(/ $readini($mircini, text, commandchar), $left($1, 1), 32)) && (!$ctrlenter) && (!$inpaste) {
    var %a
    $null($regsub($1-, m/ ?([?!])\1+/g, \1, %a))
    msg $chan %a
    halt
  }
}
Posted By: LostShadow Re: Input event questions. - 22/05/05 03:56 PM
Hm sorry I don't get yours Sigh_. I tried it in an if statement, /say the whole thing etc. And tidy_trax yours doesn't work for me. Did you actually define %a?
Posted By: tidy_trax Re: Input event questions. - 22/05/05 04:02 PM
Yes, %a is defined.
I tested it with an echo to see what would happen and it works fine:

Code:
alias test {
  var %a
  $null($regsub($1-, m/ ?([?!])\1+/g, \1, %a))
  echo -a msg $!chan %a
  halt
}


Quote:
Input: /test a???!!! b!?? c?!!
Output: msg $chan a?! b!? c?!
Posted By: DaveC Re: Input event questions. - 22/05/05 08:24 PM
love the useage of $null
Posted By: tidy_trax Re: Input event questions. - 22/05/05 09:27 PM
You can use any other non-existant identifier too:

Code:
alias t $¯($findfile($mircdir, *, 1, echo -a $1-))


/t
Posted By: qwerty Re: Input event questions. - 23/05/05 09:45 AM
The only problem is that it might not be inexistant, somebody might have a /null alias.
Posted By: tidy_trax Re: Input event questions. - 23/05/05 03:42 PM
Of course.
That's a problem with almost everything.
Posted By: FiberOPtics Re: Input event questions. - 10/10/05 06:18 PM
Ok, I know I'm late to answer but what qwerty means is that once there is infact a custom null alias, your code cannot be escaped. In the case of commands, we can always escape with an exclamation mark ! as you know, but this is not possible with identifiers.

I know about the $~<identifier> hack, though it does not work to use as you would use $null.

//echo -a $~null($regex(1,/(\d)/)) -> $regml(1)

vs

//echo -a $null($regex(1,/(\d)/)) -> $regml(1)

That's the main reason I'll never use $null in a construct such as you displayed (I saw Online do that 2 years ago as well), as it's unescapable.
© mIRC Discussion Forums