MUSHclient Question

by Okin

Back to Mechanic's Corner.

Okin2007-06-29 03:53:18
I'm trying to code a system for my hexes, and the bit I'm stuck on is trying to create an alias "h * * ..." etc so I can type "h ep fe im", for example, and have the variables hex1 = epilepsy, hex2 = fear, hex3 = impatience. The alias should be able to catch up to six hexes, but shouldn't -have- to have six. So if I just want to do "h ep", I still want hex1 = epilepsy... and I don't know how to do that. smile.gif

Oh, I'm using VBScript. Any help would be massively appreciated. biggrin.gif
Theomar2007-06-30 18:27:36
Well, in theory, you'd have an alias, "^h (.*)$" (in regexp), that passes its (.*) to a function in your script file.

You would then break that down into substrings and have a check for each hex type.

I don't know Lua enough to program a plugin for you to do that, and I don't know VBScript at all. If it was in Java, I'd be able to do it in a heartbeat.
Unknown2007-07-02 09:12:06
Actually, I'd do the regex more like ^h( \\w+{1,6})$ You might need ^h( (?:\\w+){1,6})$ but the first one should work

Then just send all the value to your script.

Your script should look something like this: (I just kinda Googled VBscript regexps, so you might need to modify it slightly. It's also rather inelegant, since I'm trying to preserve the original structure in the interest of keeping it functional.)

CODE
Sub HexThemBitches (hexes)
    Dim regEx

    Set regEx = New RegExp
    regEx.IgnoreCase = True
    regEx.Global = True

'---FEAR
    regEx.Pattern = "fe|fea|f"
    hexes = regEx.Replace(hexes, "fear")
'---EPILEPSY
    regEx.Pattern = "ep|epi|shake\\'n\\'bake"
    hexes = regEx.Replace(hexes, "epilepsy")

    world.send "VERB FOR HEXING " & hexes
End Sub



In theory that should do it. The regular expressions do two things. First, you can use the same hex more than once without having to reiterate through the list and second, you can use more than one phrase to match each hex.

If anyone wants to condense it, feel free. I've never done much with regex replacement, and certainly not in VBscript. If it doesn't work, let me know.



Edit: *sigh* I went ahead and looked up an easier way. Basically, unless you need to use the regex (mostly for being able to use multiple string to match a particular hex) you can just do this.
CODE
Sub HexThemBitches (hexes)
    Replace(hexes, "fe", "fear")
    Replace(hexes, "ep", "epilepsy")
    world.send "VERB FOR HEXING " & hexes
End Sub


But regexps are still sexy and you should use them whenever possible. VBscript, however, is not.
Okin2007-07-02 11:07:10
Thank you! worthy.gif
Sylphas2007-07-02 11:29:03
QUOTE(requiem dot exe @ Jul 2 2007, 05:12 AM) 422225
But regexps are still sexy and you should use them whenever possible. VBscript, however, is not.

Agreed. That's also a far, far easier way to do it than the one I had when I was doing mine in Python.