mIRC Homepage
Posted By: Felpipe Adding a character between text - 02/12/05 04:49 PM
Sorry for bothering so much lol
now my question is... how can I use the input so when I write whatever it would add some characters at the begining and the end ?

ex. ( I type ) "Hello"
and it would send this instead " Hello "

I know there are alwaready some posts about Inputs but no1 was helpfull to me.

Thank you.
Posted By: MikeChat Re: Adding a character between text - 02/12/05 05:36 PM
on *:input:*:{
;; checking to see if you typed "/" so you can enter a command and
;; not have this script prevent it with a garbage prefix
if ($left($1,1) == $readini($mircini,text,commandchar) { return }

;; creating a value in a variable that will be used to select which
;; of the "decorations" to use
var %decor.opt = $rand(1,3)

;; setting the left and right option
if (%decor.op == 1) {
var %decor.left = >*<
var %decor.right = >*<
}

if (%decor.op == 2) {
var %decor.left = >@<
var %decor.right = >@<
}

if (%decor.op == 3) {
var %decor.left = >^<
var %decor.right = >^<
}

;; sending the decorated string to the active window
msg $active %decor.left $$1- %decor.right

;; halting the text that would normally be sent to the window
haltdef

}
Posted By: Felpipe Re: Adding a character between text - 02/12/05 06:11 PM
thx for answering!

I get this when I run it

* /if: invalid format (line 4, script2.mrc)

if ($left($1,1) == $readini($mircini,text,commandchar) { return }

Thx again
Posted By: MikeChat Re: Adding a character between text - 02/12/05 06:46 PM
if ($left($1,1) == $readini($mircini,text,commandchar)) { return }

I missed a )
Posted By: Felpipe Re: Adding a character between text - 03/12/05 01:18 AM
Thx Again !
Posted By: FiberOPtics Re: Adding a character between text - 03/12/05 02:14 AM
Some pointers:

  • You should check if the active window is one where you can /msg to, like a channel/query/chat window.

    --> if ($istok(channel query chat,$window($active).type,32))
  • The default command char is always /, even if you change it in the options, so if you're going to check for $left($1,1) being equal to $readini($mircini,text,commandchar), you should also check it being equal to /.

    --> if ($istok(/ $readini($mircini,text,commandchar),$left($$1,1),32)
  • One thing I always add in on input events, is a check for $ctrlenter. Thanks to ctrlenter, you have a quick method to override the scripted action when sending something to the server. Say for example you have a nick completer, but this time you don't want it to format anything, well you type your text, and then press ctrl+enter.

    --> if ($ctrlenter) return
  • You can save some processing time, by making mIRC parse less.

    var %decor.opt = $rand(1,3)

    That means %decor.opt will have a value that is either 1, 2 or 3. It can never be multiple values at once, therefore it is advised to use elseif when doing for checks.

    if (%decor.opt == 1) {
    ; do things when %decor.opt equals 1
    }
    elseif (%decor.opt == 2) {
    ; do things when %decor.opt equals 2
    }

    Let's say %decor.opt is 1, it will then trigger that first if check. After it has finished the code within the braces { }, mIRC's parser will continue parsing now going to "if (%decor.opt == 2)" in your code, which means it must evalute %decor.opt again, and check if it's equal to 2.

    Since 1 can never be 2 or 3, you can put elseif. mIRC's parser will encounter the elseif, and will not continue parsing the elseif condition, because it knows an if condition was already met.

    Now of course, in reality you will never notice any speed difference for such a small script, but the speed is not the issue, from a programming/scripting perspective, it is simply more logical and "correct" to use elseif where due.
  • You use $$1- in when messaging to the active window, but it would be smarter to put that in your first if check where you do $left($1,1) etc. If you put $left($$1,1), the script will already halt, again avoiding doing unnecessary work.
Posted By: MikeChat Re: Adding a character between text - 03/12/05 05:28 AM
Some pointers:

  • You should check if the active window is one where you can /msg to, like a channel/query/chat window.
  • I don't chat in the status window much...

    --> if ($istok(channel query chat,$window($active).type,32))
  • The default command char is always /, even if you change it in the options, so if you're going to check for $left($1,1) being equal to $readini($mircini,text,commandchar), you should also check it being equal to /.

    --> if ($istok(/ $readini($mircini,text,commandchar),$left($$1,1),32)
  • good to know, I doubt that it applies in this case
  • One thing I always add in on input events, is a check for $ctrlenter. Thanks to ctrlenter, you have a quick method to override the scripted action when sending something to the server. Say for example you have a nick completer, but this time you don't want it to format anything, well you type your text, and then press ctrl+enter.

    --> if ($ctrlenter) return
  • normally I include that in fact I have an alias-identifier I use that covers that and more.
  • You can save some processing time, by making mIRC parse less.

    var %decor.opt = $rand(1,3)

    That means %decor.opt will have a value that is either 1, 2 or 3. It can never be multiple values at once, therefore it is advised to use elseif when doing for checks.

    if (%decor.opt == 1) {
    ; do things when %decor.opt equals 1
    }
    elseif (%decor.opt == 2) {
    ; do things when %decor.opt equals 2
    }

    Let's say %decor.opt is 1, it will then trigger that first if check. After it has finished the code within the braces { }, mIRC's parser will continue parsing now going to "if (%decor.opt == 2)" in your code, which means it must evalute %decor.opt again, and check if it's equal to 2.

    Since 1 can never be 2 or 3, you can put elseif. mIRC's parser will encounter the elseif, and will not continue parsing the elseif
    condition, because it knows an if condition was already met.

    Now of course, in reality you will never notice any speed difference for such a small script, but the speed is not the issue, from a programming/scripting perspective, it is simply more logical and "correct" to use elseif where due.
  • good to know btw roughly how much time will it save in each if/elseif?
  • You use $$1- in when messaging to the active window, but it would be smarter to put that in your first if check where you do $left($1,1) etc. If you put $left($$1,1), the script will already halt, again avoiding doing unnecessary work.
  • yup

maybe you can just write one up and post it instead of mine
Posted By: Sigh Re: Adding a character between text - 03/12/05 07:39 AM
Since this comes up somewhat frequently, I suppose it's worth mentioning you could check:

Code:
if ($left($1,1) isin / $readini($mircini,text,commandchar)) 


In place of the $istok
Posted By: MikeChat Re: Adding a character between text - 03/12/05 05:08 PM
Thanks Sigh, I will be replacing what I have in my default input check alias with that.
Posted By: FiberOPtics Re: Adding a character between text - 03/12/05 06:28 PM
Heh, that does exactly the same as the $istok does :rolleyes:
Posted By: stickydank Re: Adding a character between text - 03/12/05 11:40 PM
well u could just use addon
like AM ACROS
Posted By: Felpipe Re: Adding a character between text - 05/12/05 02:20 AM
thx alot u guys thats all really helpfull thx again
© mIRC Discussion Forums