|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
OP
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
I'm trying to make the background color appear 50/50, and I seem to have run into a stone wall. This is what I have attempted to do with regsubex, but it doesn't quite work out the way I want it to be: on *:input:#:{
if $left($1,1) != / { var %1 12,11, %2 11,14
echo # $+($regsubex($1-,/(.)/g,$iif(2 \\ \n,$+($chr(3),%1,\1))),$&
$regsubex($1-,/(.)/g,$iif(2 \\ \n,$+($chr(3),%2),\1))) | haltdef
}
} The text itself looks jumbled. If anyone has a better idea, please show me the way.
|
|
|
|
Joined: Feb 2006
Posts: 523
Fjord artisan
|
Fjord artisan
Joined: Feb 2006
Posts: 523 |
i think this is what you're trying to get at:
if ($left($1,1) != /) {
var %1 12,11, %2 11,14
echo # $regsubex($1-,/(?!$)/g,$chr(3) $+ $iif(2 \\ \n,%1,%2))
haltdef
}
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
OP
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
Not quite, jaytea. I would like it to appear as: 
|
|
|
|
Joined: Oct 2004
Posts: 8,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
Why not just use $len()? Here's just a quick example. You could improve on this by combining some things to reduce some calculations, but I wanted it to clearly show what was happening.
on *:input:#:{
if $left($1,1) != / {
var %1 12,11, %2 11,14, %l = $int($calc($len($1-) / 2)), %r = $round($calc($len($1-) / 2),0)
echo # %1 $+ $left($1-,%l) $+ %2 $+ $right($1-,%r)
haltdef
}
}
|
|
|
|
Joined: Dec 2002
Posts: 294
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Dec 2002
Posts: 294 |
For an ON INPUT event, I'd recommend checking $ctrlenter. Also, you should be using /say, not just /echo, or you won't send the text off to the channel... unless that was your intention? on *:INPUT:#:{
if (($ctrlenter) || ($left($1,1) == /)) { return }
etc
}
Last edited by drum; 16/06/10 05:35 PM.
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
OP
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
I appreciate the suggestion, Riamus2. You've solved my puzzle. Thank you very much.
drum, I know that. Thanks for the input! The reason I used echo instead of /say or /msg # is that I was testing it to make sure it's going to work out the way I'm after.
|
|
|
|
Joined: Feb 2009
Posts: 133
Vogon poet
|
Vogon poet
Joined: Feb 2009
Posts: 133 |
like this var %x $len($1-) / 2,%1 12,11,%2 11,14
say $regsubex($1-,/(.)/g,$iif(%x < \n,%2,%1)\1)
haltdef remember u have to check if mode c isin channel mode or not if c !isincs $gettok($chan($active).mode,1,32)
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
OP
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
Very, very good. chacha. That is shorter compared to Riamus2's.
|
|
|
|
Joined: Feb 2009
Posts: 133
Vogon poet
|
Vogon poet
Joined: Feb 2009
Posts: 133 |
tks Tomao 
|
|
|
|
Joined: Feb 2006
Posts: 523
Fjord artisan
|
Fjord artisan
Joined: Feb 2006
Posts: 523 |
if short is what you want, there's still ways to go :P it may be shorter, but it adds superfluous color codes; there's no reason to insert them between every character
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
OP
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
My eyes are peeled, Jeytea, for when you want to enlighten me with some short variations.
|
|
|
|
Joined: Feb 2006
Posts: 523
Fjord artisan
|
Fjord artisan
Joined: Feb 2006
Posts: 523 |
shortening code on mirc is generally a thought provoking exercise which can be lots of fun, but there is a time and a place and often more important things to consider. here, we merely need to insert a string of text in the middle of another. invoking $regsubex() with $iif() testing a condition for every character in $1- is, quite simply, overkill. not to mention adding 6 characters for every 1 in the input string, reducing the amount of text we're able to send the server by a factor of 7. the following method is simpler, generates a much shorter string and is 8 bytes shorter than the other:
var %i $len($1-) / 2
say 12,11 $+ $left($1-,%i) $+ 11,14 $+ $mid($1-,- $+ %i)
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
|
|
|
|
Joined: Feb 2009
Posts: 133
Vogon poet
|
Vogon poet
Joined: Feb 2009
Posts: 133 |
not realy good test for test return test fr test <== that messing the "o" then u have to add $calc and u'll have more bytes var %i $len($1-) / 2
say 12,11 $+ $left($1-,%i) $+ 11,14 $+ $mid($1-,- $+ $calc(%i +1)) if you want even less bytes var %x $len($1-) / 2,%1 12,11
say 11,14 $regsubex($1-,/(.)/g,$iif(%x < \n,%1)\1) with identifiers $left and $mid it's cleaner, but what interress is the result
|
|
|
|
Joined: Feb 2006
Posts: 523
Fjord artisan
|
Fjord artisan
Joined: Feb 2006
Posts: 523 |
ye, i should have used $right($1-,- $+ %i) in place of $mid($1-,- $+ %i), there's no need for $calc(). do you honestly think code is not interesting unless you use $regsubex or other methods that are flagrantly unnecessary? it leads me to believe you didn't read or understand what i was saying earlier about code suitability and the drawbacks of using your approach.
and you can still get shorter code with $regsubex, but i'll leave that as an exercise for you ;P
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
|
|
|
|
Joined: Feb 2009
Posts: 133
Vogon poet
|
Vogon poet
Joined: Feb 2009
Posts: 133 |
and you can still get shorter code with $regsubex, but i'll leave that as an exercise for you ;P lol  we r not in challenge here :p btw i didnt say that with $regsubex is better
|
|
|
|
|