Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ General ➜ Sending Alternate text colours per word to the mud...

Sending Alternate text colours per word to the mud...

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2 

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #15 on Mon 25 Apr 2005 09:16 PM (UTC)
Message
I tried that. Couldn't get it to work.

I need the alias to be sayto * *

I don't know enough about regular expressions to make it work.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #16 on Mon 25 Apr 2005 09:48 PM (UTC)
Message
Are you only going to be using single spaces in between? If so, you could just use split. I suppose that would even work for multiples of spaces (except you'd skip a color, but that probably wouldnt be a problem).

Actually, here it is (as a function), provided that it only uses certain delimiters (you can specify) so a space and a tab in the same thing won't work. And that if you have duplicate spaces, you'll 'skip' a color (Youll have a space, a color code, another space, then another colorcode).


function colorize (sLine, sSplit)
dim codes, tokens
dim uCodes, uTokens 'lengths (UBound)
dim i
codes = array("^^","^o","^W")
tokens = split(sLine,sSplit)
uCodes = UBound(codes)
uTokens = UBound(tokens)
for i = 0 to uTokens
  tokens(i) = codes(i mod (uCodes+1)) & tokens(i)
next
colorize = join(tokens,sSplit)
end function

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #17 on Mon 25 Apr 2005 10:04 PM (UTC)

Amended on Mon 25 Apr 2005 10:06 PM (UTC) by Flannel

Message
Actually, this one is better, it uses a regexp:

To do what you want, you'll pass your string (to be colored) and the regexp: "\s*\w+\s*"
You will always have to pass the regexp, but you could easily hardcode that regexp into it (and remove the parameter) if that's all you'll ever be doing with this function.
By making this line:regEx.pattern = reSplit
and making reSplit be the regexp ("\s*\w+\s*")

function colorize (sLine, reSplit)
dim codes, colored
dim uCodes, i 'lengths (UBound)
dim regEx, Matches, Match
codes = array("^^","^o","^W")
uCodes = UBound(codes)
Set regEx = New RegExp
regEx.pattern = reSplit
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(sLine)
i = 0
colored = ""
for each Match in Matches
  colored = colored & codes(i mod (uCodes+1)) & Match
  i = i + 1
next
colorize = colored
end function

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #18 on Mon 25 Apr 2005 10:19 PM (UTC)
Message
Well, I got sayto to work. Actually, my friend got it to work just fine.

Even got it to work embedded into the alias itself.


The problem now is it's dropping the punctuation on the last word. It doesn't drop it in the middle of the array though, just on the UBound word.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #19 on Mon 25 Apr 2005 10:48 PM (UTC)

Amended on Mon 25 Apr 2005 11:58 PM (UTC) by Flannel

Message
Ah yes, punctuation.
Try this regexp:
"\s*\S+\s*"

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #20 on Mon 25 Apr 2005 11:14 PM (UTC)
Message
Aliases with code embedded.
<aliases>
  <alias
   match="^(sayto)([ \t]+\b.*\b)+.*$"
   enabled="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   keep_evaluating="y"
   sequence="10"
  >
  <send>dim string
Colored = "%1"
string = split("%2")
Size = UBound(string)
randomnumber = (Int((6-1+1)*Rnd+min))
select case randomnumber
	case "1"
		codes = Array("^o","^W","^^")
	case "2"
		codes = Array("^o","^^","^W")
	case "3"
		codes = Array("^W","^o","^^")
	case "4"
		codes = Array("^W","^^","^o")
	case "5"
		codes = Array("^^","^W","^o")
	case Else
		codes = Array("^^","^o","^W")
end select
Colored = Colored &amp; " " &amp; string(1)
	For i = 2 to size Step 1
		Colored = Colored &amp; " " &amp; codes((i-1) mod (UBound(codes)+1)) &amp; string(i)
	Next
Colored = Colored &amp; "^^"
Send Colored</send>
  </alias>
  <alias
   match="^(yell|say|ic)([ \t]+\b.*\b)+.*$"
   enabled="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   keep_evaluating="y"
   sequence="10"
  >
  <send>Colored = "%1"
string = split("%2")
Size = UBound(string)
randomnumber = (Int((6-1+1)*Rnd+min))
select case randomnumber
 case "1"
  codes = Array("^o","^W","^^")
 case "2"
  codes = Array("^o","^^","^W")
 case "3"
  codes = Array("^W","^o","^^")
 case "4"
  codes = Array("^W","^^","^o")
 case "5"
  codes = Array("^^","^W","^o")
 case Else
  codes = Array("^^","^o","^W")
end select
 For i = 1 to size Step 1
  Colored = Colored &amp; " " &amp; codes((i-1) mod (UBound(codes)+1)) &amp; string(i)
 Next
Colored = Colored &amp; "^^"
Send Colored</send>
  </alias>
</aliases>
Ok, but not sure where to put that in the current alias that I have.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #21 on Tue 26 Apr 2005 12:13 AM (UTC)

Amended on Tue 26 Apr 2005 12:15 AM (UTC) by Flannel

Message
Suggest you get rid of the aliases you have, and make it a function (my second one, the regexp). Then your aliases become this simple:


<aliases>
  <alias
   match="^(say|ic|yell) (.*)$"
   enabled="y"
   echo_alias="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   keep_evaluating="y"
   sequence="100"
  >
  <send>send "%1 " &amp; colorizeRand("%2","\\s*\\S+\\s*") &amp; "^^"</send>
  </alias>
  <alias
   match="^sayto (\w+) (.*)$"
   enabled="y"
   echo_alias="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   keep_evaluating="y"
   sequence="100"
  >
  <send>send "sayto %1 " &amp; colorizeRand("%2","\\s*\\S+\\s*") &amp; "^^"</send>
  </alias>
</aliases>


And the code (since I renamed it colorizeRand to reflect the random color, you can change it back of course):

Randomize
function colorizeRand (sLine, reSplit)
dim codes, colored
dim uCodes, i 'length (UBound)
dim regEx, Matches, Match
'codes = array("^^","^o","^W")
'Start Randomization
i = Int(6*Rnd)
select case (i)
  case 0
    codes = Array("^o","^W","^^")
  case 1
    codes = Array("^o","^^","^W")
  case 2
    codes = Array("^W","^o","^^")
  case 3
    codes = Array("^W","^^","^o")
  case 4
    codes = Array("^^","^W","^o")
  case else 'we could do 5, but just incase
  'someone edits something they shouldn't
    codes = Array("^^","^o","^W")
end select
'End Randomization
uCodes = UBound(codes)
Set regEx = New RegExp
regEx.pattern = reSplit
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(sLine)
i = 0
colored = ""
for each Match in Matches
  colored = colored & codes(i mod (uCodes+1)) & Match
  i = i + 1
next
colorizeRand = colored
end function


~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #22 on Tue 26 Apr 2005 12:21 AM (UTC)
Message
That works, except when you start putting numbers in there.

You say '2'
You say '1'
You say 'x 3'
You say '1 2'
You say '1 2 x'
You say '1 x 3 4'
You say 'x 2 3 x 5'
You say '1 x 3 4 x 6'
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #23 on Tue 26 Apr 2005 12:26 AM (UTC)

Amended on Tue 26 Apr 2005 12:30 AM (UTC) by Flannel

Message
What doesn't work? It works fine for me. What version of everything are you using? My latest one?

Edit:
Oh, and you'll probably want to uncheck "echo alias" once you get down to actually using it. Or SendNoEcho, or whatever other permutation of that.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #24 on Tue 26 Apr 2005 12:28 AM (UTC)

Amended on Tue 26 Apr 2005 12:32 AM (UTC) by David Berthiaume

Message
Yes, I copy and pasted your aliases, and the code.

When you(I mean myself) type say 1 2 3 4 5 6 7

It does this:

You say '1 2 x 4 5 x 7'

EDIT: Apparently the x's show up depending upon thecolor codes. If you do 1 2 3 4 5 6 7 several times, the x blots out certain numbers depending on the color codes.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #25 on Tue 26 Apr 2005 12:35 AM (UTC)
Message
say 1 2 3 4 5 6 7
say ^W1 ^o2 ^^3 ^W4 ^o5 ^^6 ^W7^^
You say "^W1 ^o2 ^^3 ^W4 ^o5 ^^6 ^W7^^"


Could it maybe be the color codes eating characters? Since, obviously that isn't a problem for me (my colors aren't parsed, obviously). It's sending what it's supposed to be sending.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #26 on Tue 26 Apr 2005 12:37 AM (UTC)
Message
Yeah. So, it's a problem with the server (or a combination of color codes and numbers), and not the alias (you can see what you're sending as it echos and verify that they are infact being sent correctly, just echod incorrectly).

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #27 on Tue 26 Apr 2005 12:47 AM (UTC)
Message
Yeppers, nothing wrong with the code, it's a server issue with using the default color and a number together.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #28 on Tue 26 Apr 2005 12:55 AM (UTC)

Amended on Tue 26 Apr 2005 12:57 AM (UTC) by Flannel

Message
You could send to execute (you WILL need to do world.execute, since otherwise you'll hit the VBScript execute) and then replace any ^^\d+ with ^^ \d+ with an alias (except, you would hit this alias again. So... I guess you'd need to change this alias to send something else and then make that one send it on completely).

Or you could just do it before sending internally in this alias. Or find another color code (or some other work around). I'm sure there are other options that the server introduces as well.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


68,781 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.