mIRC Home    About    Download    Register    News    Help

Print Thread
Adding a character between text #136728 02/12/05 04:49 PM
Joined: Nov 2003
Posts: 82
F
Felpipe Offline OP
Babel fish
OP Offline
Babel fish
F
Joined: Nov 2003
Posts: 82
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.

Re: Adding a character between text #136729 02/12/05 05:36 PM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
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

}

Re: Adding a character between text #136730 02/12/05 06:11 PM
Joined: Nov 2003
Posts: 82
F
Felpipe Offline OP
Babel fish
OP Offline
Babel fish
F
Joined: Nov 2003
Posts: 82
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

Re: Adding a character between text #136731 02/12/05 06:46 PM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
if ($left($1,1) == $readini($mircini,text,commandchar)) { return }

I missed a )

Re: Adding a character between text #136732 03/12/05 01:18 AM
Joined: Nov 2003
Posts: 82
F
Felpipe Offline OP
Babel fish
OP Offline
Babel fish
F
Joined: Nov 2003
Posts: 82
Thx Again !

Re: Adding a character between text #136733 03/12/05 02:14 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.


Gone.
Re: Adding a character between text #136734 03/12/05 05:28 AM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
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

Re: Adding a character between text #136735 03/12/05 07:39 AM
Joined: Aug 2003
Posts: 314
S
Sigh Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
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

Re: Adding a character between text #136736 03/12/05 05:08 PM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
Thanks Sigh, I will be replacing what I have in my default input check alias with that.

Re: Adding a character between text #136737 03/12/05 06:28 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Heh, that does exactly the same as the $istok does :rolleyes:


Gone.
Re: Adding a character between text #136738 03/12/05 11:40 PM
Joined: Oct 2005
Posts: 51
S
stickydank Offline
Babel fish
Offline
Babel fish
S
Joined: Oct 2005
Posts: 51
well u could just use addon
like AM ACROS

Re: Adding a character between text #136739 05/12/05 02:20 AM
Joined: Nov 2003
Posts: 82
F
Felpipe Offline OP
Babel fish
OP Offline
Babel fish
F
Joined: Nov 2003
Posts: 82
thx alot u guys thats all really helpfull thx again