That will capture it, what script language are we using? Since I'd hate to code it and then have it be the wrong one.
That regexp can be tweaked to suit needs (like getting rid of the leading space, but then it'd be every second wildcard, etc) but that too depends on the script routine. So, what are we coding it in?
Coding in VBscript right now. I learned on it, and I know it more than I know Lua... Hard to switch over when you've had a couple of computer crashes to contend with and lose a lot of stuff.
Actually, that regexp was wrong, since, the \ws should have been \bs, and the space infront is now going to be \s+
Im worried about hyphenated words, but I think that setup should work.
New regexp becomes:
^(say|ic|yell)([ \t]+\b.*\b)+.*$
And we're going to be using a script file (because cycling through an array is much easier than trying to figure out how many wildcards we have inside the trigger).
And this could still all change (the regexp will probably change at least once more, just for fun).
Unless you haven't put up the code that is the words and colorized... Did I miss something?
EDIT: Oh yeah, additionally... There is also sayto <name> <string>
That'll probably have to be a seperate alias, which is fine, and should be easy enough to make once I have the script itself. It's just adding in another wildcard, no biggie
Yeah, that trigger was script-less, it was just the trigger. I figured I might as well post that, since I needed to ask you what language anyway.
This is what I have thus far for the script (obviously it doesn't work).
The problem (as far as I can tell) is the trigger. Since it's not returning one word per wildcard. The commented lines (at the beginning) should (once everything works correctly) have one word per line.
I'm going to reread some of the basics of MC and scripts, since obviously I'm forgetting something (there are always 10 array pieces passed, regardless of how many wildcards there actually are?).
If that's true, then it looks like doing it via send to script may end up being more convenient (and feasible) anyway.
Option Explicit
Sub colorize (sName, sLine, aryWild)
dim size
dim Colored
dim codes
'DEBUG TRIGGER
' for i = LBound(aryWild) to UBound(aryWild)
' note i & ": " & aryWild(i)
' next
codes = Array("^o","^W","^^") 'color codes
size = UBound(aryWild) '1+3X+1?
'except its length-1, so we dont need to
'subtract the 1 for the say/ic/yell
Colored = aryWild(1)
dim i
For i = 2 to size Step 3
'aryWild(i) whole thing
'aryWild(i+1) whitespace
'aryWild(i+2) word
Colored = Colored & aryWild(i+1)
Colored = Colored & codes(((i-1) mod 9)/(UBound(codes)+1))
'append the color code (i-1) mod 9 is 0,3,6
'divided by codes length (Ubound + 1) gives a corresponding
'array element (0,1,2), this way you can simply change the
'codes aray and not have to change anything else
Colored = Colored & aryWild(i+2) 'append word
Next
Colored = Colored & aryWild(size) 'last bit
Send Colored 'can't forget this
End Sub
Something similar, I think what we're missing in this particular case is the split command...
sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Did a little experimenting on my own with this. I don't know if it'll help. But here's what I got.
Sub colorize (sName, sLine, aryWild)
dim string, i
string = split (aryWild(1))
for i = LBound(string) to UBound(string)
note i & ": " & string(i)
next
End Sub
Hope this helps a little bit atleast.
I searched the forums for one of my OLD postings with Autocombo. I knew that Lbound and Ubound were going to come into play with this, it was the rest I wasn't sure about. When you didn't put a split in there, it got me to thinking about the autocombo script Nick helped me write. I started fiddling with it. and I got it to note properly, I just do not know how to incorperate the split into the rest of your code you put up there. I think once that is done it will work very well.
Sub colorize3 (sName, sLine, aryWild)
dim size
dim Colored
dim codes
dim string
string = split(aryWild(2))
for i = LBound(string) to UBound(string)
next
codes = Array("^o","^W","^^")
size = UBound(string) '1+3X+1?
Colored = aryWild(1)
dim i
For i = 2 to size Step 3
Colored = Colored & aryWild(i+1)
Colored = Colored & codes(((i-1) mod 9)/(UBound(codes)+1))
Colored = Colored & aryWild(i+2) 'append word
next
Colored = Colored & arywild(2) 'last bit
Note Colored
End Sub
Sub colorize3 (sName, sLine, aryWild)
dim size, Colored, codes, string
string = split(aryWild(2))
for i = LBound(string) to UBound(string)
next
codes = Array("^o","^W","^^") 'color codes
for i = LBound(codes) to UBound(codes)
next
size = UBound(string) '1+3X+1?
'except its length-1, so we dont need to
'subtract the 1 for the say/ic/yell
Colored = aryWild(1)
dim i
For i = 1 to size Step 1
Colored = Colored & " " & codes(((i-2) mod 7)/(UBound(codes)+1)) & string(i)
Next
Send Colored
End Sub
The problem as you'll see when you use it. It won't change every other word. Perhaps you can figure out where the error in the step is. I dunno. It's doing something funky, I don't understand that whole mod thing. That's probably where my error is. But I got it semi-working. More than it was before.
Final Working Code. Thanks to my friend Nomad who helped me out
Sub colorize3 (sName, sLine, aryWild)
dim size, Colored, codes, String, i, x
Colored = aryWild(1)
string = split(aryWild(2))
for x = LBound(string) to UBound(string)
next
Size = UBound(string)
codes = Array("^W","^^","^o")
for i = LBound(codes) to UBound(codes)
Next
For i = 1 to size Step 1
Colored = Colored & " " & codes((i-1) mod (UBound(codes)+1)) & string(i)
Next
Colored = Colored & "^^"
send Colored
End Sub
All you're doing is making the beginning thing different. You could reuse the script and just join the first and second thing (instead of ic the first thing is "sayto bob") in the script and then sent to the colorize routine.
Why do you have empty fors? You have two:
for x = LBound(string) to UBound(string)
next
and another with i, that do absolutely nothing.
You could change your colorize code to be a subroutine that doesn't send, and that doesn't worry about anything except coloring, then you could handle the specific i/o (including the prefix) outside of the colorize sub.
I guess a function would be easiest, since then you could return the string.
Actually, if you're going to do that, having the function itself figure out the splitting stuff might be best (pass it a string, it tokenizes it, adds color codes, and returns the new string).
Then you could use it whenever you wanted, in whatever context you wanted.
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
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
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
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.
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.
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.
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).
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.