mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline OP
Hoopy frood
OP Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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:
Code:
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: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
i think this is what you're trying to get at:

Code:
  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,129
T
Tomao Offline OP
Hoopy frood
OP Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Not quite, jaytea. I would like it to appear as:

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.

Code:
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
  }
}


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2002
Posts: 344
D
Pan-dimensional mouse
Offline
Pan-dimensional mouse
D
Joined: Dec 2002
Posts: 344
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?

Code:
on *:INPUT:#:{
  if (($ctrlenter) || ($left($1,1) == /)) { return }

  etc
}

Last edited by drum; 16/06/10 05:35 PM.
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline OP
Hoopy frood
OP Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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
C
Vogon poet
Offline
Vogon poet
C
Joined: Feb 2009
Posts: 133
like this
Code:
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

Code:
if c !isincs $gettok($chan($active).mode,1,32)


WorldDMT
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline OP
Hoopy frood
OP Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Very, very good. chacha. That is shorter compared to Riamus2's.

Joined: Feb 2009
Posts: 133
C
Vogon poet
Offline
Vogon poet
C
Joined: Feb 2009
Posts: 133
tks Tomao smile


WorldDMT
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
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,129
T
Tomao Offline OP
Hoopy frood
OP Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
My eyes are peeled, Jeytea, for when you want to enlighten me with some short variations.

Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
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:

Code:
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
C
Vogon poet
Offline
Vogon poet
C
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

Code:
var %i $len($1-) / 2
say 12,11 $+ $left($1-,%i) $+ 11,14 $+ $mid($1-,- $+ $calc(%i +1))



if you want even less bytes

Code:
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


WorldDMT
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
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
C
Vogon poet
Offline
Vogon poet
C
Joined: Feb 2009
Posts: 133
Quote:
and you can still get shorter code with $regsubex, but i'll leave that as an exercise for you ;P

lol laugh we r not in challenge here :p
btw i didnt say that with $regsubex is better


WorldDMT

Link Copied to Clipboard