mIRC Home    About    Download    Register    News    Help

Print Thread
$replace #67766 14/01/04 04:01 AM
Joined: Jan 2004
Posts: 6
F
flugger Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jan 2004
Posts: 6
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 ?

Re: $replace #67767 14/01/04 04:24 AM
Joined: Apr 2003
Posts: 426
neophyte Offline
Fjord artisan
Offline
Fjord artisan
Joined: Apr 2003
Posts: 426
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.


--------
mIRC - fun for all the family (except grandma and grandpa)
Re: $replace #67768 14/01/04 05:21 AM
Joined: Jan 2004
Posts: 6
F
flugger Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jan 2004
Posts: 6
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.

Re: $replace #67769 14/01/04 05:44 AM
Joined: Jan 2004
Posts: 6
F
flugger Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jan 2004
Posts: 6
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

Re: $replace #67770 14/01/04 08:34 AM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
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


-KingTomato
Re: $replace #67771 14/01/04 03:11 PM
Joined: Jan 2004
Posts: 26
F
Fibsi Offline
Ameglian cow
Offline
Ameglian cow
F
Joined: Jan 2004
Posts: 26
" ...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).

Re: $replace #67772 14/01/04 03:17 PM
Joined: Dec 2003
Posts: 33
M
Man Offline
Ameglian cow
Offline
Ameglian cow
M
Joined: Dec 2003
Posts: 33
edit: oops, nm just use what KingTomato has put in.

Re: $replace #67773 15/01/04 01:33 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
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.

Re: $replace #67774 15/01/04 02:26 AM
Joined: Jan 2004
Posts: 6
F
flugger Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jan 2004
Posts: 6
King Tomotoes script works ~almost~ perfectly.
But when I do an action


/me does whatever is displayed in the channel.


Re: $replace #67775 15/01/04 03:00 AM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
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


-KingTomato
Re: $replace #67776 15/01/04 04:06 AM
Joined: Jan 2004
Posts: 6
F
flugger Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jan 2004
Posts: 6
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..

?