mIRC Homepage
Posted By: flugger $replace - 14/01/04 04:01 AM
I am not very good at scripting and I know this should be fairly simple.

I simply want to replace my text for certain words to say something different.

for example....if I type 'brnday' I would want it to display 'brandy' in the channel. I know it is probably a simple on INPUT script but I just dont know how to do it I'd also like to be able to add other words to be replaced. Answers ?
Posted By: neophyte Re: $replace - 14/01/04 04:24 AM
on *:INPUT:*:{
.msg $active $replace($1-,brnday,brandy)
}

Thats an example.

For instance, you can use $replace to replace multiple times within the one text string.

Eg:

$replace(brnday: hello how are you,brnday,brandy,you,you?)

This would replace brnday with brandy, and you, with you?


This is how it works:

$replace(text string,word to replace,new word)

I hope that helps.
Posted By: flugger Re: $replace - 14/01/04 05:21 AM
I don't know why, but that looks like it would work to me, but it just doesnt work..still comes out how I spelled it initially.
Posted By: flugger Re: $replace - 14/01/04 05:44 AM
It did however make me repeat everything I said twice. I couldn't see it but it was shown to me after I thouroughly pissed a few people off smirk
Posted By: KingTomato Re: $replace - 14/01/04 08:34 AM
Code:
on *:INPUT:*: {
  var %replacer = [color:Red]this,is,a,list,of,words,to,be,replaced[/color]
  var %replace = [color:blue]this,is,what,they,should,be,replaced,with[/color]
  var %r = 1, %msg = $1-
  while ($gettok(%replacer, %r, 44) != $null) {
    var %from = $ifmatch, %to = $iif($gettok(%replace, %r, 44), $ifmatch, %from)
    var %msg = $replace(%msg, %from, %to)
    /inc %r
  }
  /msg $active %msg
  /halt
}


that should work a little better. Basically, set the first variable (marked with red) to the word being replaced, and the blue portion to the one to replace it with. Seperate the sections with commas. For example, if you wanted all the instances of "cat" to change to "dog", and "fish" to change to "parrot", you could use:

var %replacer = cat,fish
var %replace = dog,parrot
Posted By: Fibsi Re: $replace - 14/01/04 03:11 PM
" ...make me repeat everything I said twice... "

that happens if another remote script you are running is also triggered by on INPUT { say $whatever($1-) } .

The ^ Prefix (/help Halting default text) is not supported here. AFAIK the only thing you can do is to find that 2nd on INPUT event (search all *.mrc, *.ini et cetera for ":INPUT:" (without quotes)) , then unload / delete or modify it (e.g. put a ; before /say).
Posted By: Man Re: $replace - 14/01/04 03:17 PM
edit: oops, nm just use what KingTomato has put in.
Posted By: DaveC Re: $replace - 15/01/04 01:33 AM
better than editing the other scripts just do this...

alt-r / remotes / file / order / select KingTomato's script file / move it to the top of the order.

His well no run first, and void all the ones following as his is
on *:input:*: which catches all input if im not mistaken.

one other thing you might consider is this.

Code:
 
on *:INPUT:*: {
  if (%replacer.block == $true) { set %replacer.block $false }
  else {
    var %replacer = this,is,a,list,of,words,to,be,replaced
    var %replace = this,is,what,they,should,be,replaced,with
    var %r = 1, %msg = $1-
    while ($gettok(%replacer, %r, 44) != $null) {
      var %from = $ifmatch, %to = $iif($gettok(%replace, %r, 44), $ifmatch, %from)
      var %msg = $replace(%msg, %from, %to)
      /inc %r
    }
    /editbox -an %msg
    set %replacer.block $true
    /halt
}
 


Same routine, just it loads the editbox with the result, then sets a flag to say dont process the next line comming through (being the editbox loaded line), then halts the current lines processing, on the next pass the line doesnt get processed and the flag gets cleared, this well allow what ever other ON INPUT routines in other scripts to also get to process the line.
I only said this, as i wrote a on input routine to decapatilize lines, and then it screwed up something someone elses did below it, as theres never got a chance to run.
Posted By: flugger Re: $replace - 15/01/04 02:26 AM
King Tomotoes script works ~almost~ perfectly.
But when I do an action


/me does whatever is displayed in the channel.

Posted By: KingTomato Re: $replace - 15/01/04 03:00 AM
good catch, i forgot about that >:D

Code:
on *:INPUT:*: {
  if ($left($1, 1) !isin $+(/,$readini($mircini,text,commandchar))) {
    var %replacer = [color:Red]this,is,a,list,of,words,to,be,replaced[/color]
    var %replace = [color:blue]this,is,what,they,should,be,replaced,with[/color]
    var %r = 1, %msg = $1-
    while ($gettok(%replacer, %r, 44) != $null) {
      var %from = $ifmatch, %to = $iif($gettok(%replace, %r, 44), $ifmatch, %from)
      var %msg = $replace(%msg, %from, %to)
      /inc %r
    }
    /msg $active %msg
    /halt
  }
}

that should fix it. Sorry for the foul up. >:D
Posted By: flugger Re: $replace - 15/01/04 04:06 AM
Thanks loads. I tried to fix it myself because I could see it was sending as a /msg but I couldn't do it. I tried

if(/me isin $1-) {/describe $active $1-}

etc...you can see where that would go wrong. But anyway its working now, and not interfering with any other remotes that I have found yet. So thanks.

Uhm, I hate to even ask this, but how would I modify it to also replace words on *:ACTION:*

etc..

?
© mIRC Discussion Forums