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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Tips and tricks ➜ Speedwalk conversion

Speedwalk conversion

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


Posted by Hex1   Australia  (8 posts)  Bio
Date Fri 18 May 2007 07:54 AM (UTC)

Amended on Fri 18 May 2007 07:59 AM (UTC) by Hex1

Message
I've quite a few speedwalks in the old-fashioned
"
west
north
north
north
east
"
alias-type format (along with standard abbreviations [e ne n nw w sw s se] as well as other directions/commands such as 'out'), is there any automated way to convert them to the MUSHclient "w 3n e" speedwalk-type format?

I tried to write a Delphi application to do this, but unfortunately I had to format my PC recently so all my hard (and n00by, I'm sure a pro would have it done in the blink of an eye) work was lost.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #1 on Fri 18 May 2007 08:45 AM (UTC)
Message
Here you go, in Lua:

local dirToLetter = {
    north = "n", n = "n",
    northwest = "nw", nw = "nw",
    west = "w", w = "w",
    southwest = "sw", sw = "sw",
    south = "s", s = "s",
    southeast = "se", se = "se",
    east = "e", e = "e",
    northeast = "ne", ne = "ne",
}

local commands = {}
local count = 0

for line in io.lines() do

    -- only act on non-blank lines
    if string.match(line, "%S") then

        local last = commands[#commands]

        local letter = dirToLetter[line]

        assert(letter)

        -- first?
        if not last then
            commands[1] = {letter=letter,count=1}
        else
            -- same as previous?
            if last.letter == letter then
                last.count = last.count + 1
            else
                commands[#commands+1] = {letter=letter, count=1}
            end
        end
    end
end

for _,cmd in ipairs(commands) do
    if cmd.count > 1 then
        io.write(cmd.count)
    end
    io.write(cmd.letter, " ")
end

-- blank line
print()




Here's a demo of it working:


[david@thebalrog:~]$ cat tmp.txt
north
north
east
east
sw
sw
n
n
s
s

[david@thebalrog:~]$ lua converter.lua < tmp.txt
2n 2e 2sw 2n 2s 

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Hex1   Australia  (8 posts)  Bio
Date Reply #2 on Fri 18 May 2007 09:23 AM (UTC)

Amended on Fri 18 May 2007 10:45 AM (UTC) by Hex1

Message
Wow, thank you so much! :)
Just one more tiny thing, how would you implement two word commands, notably "journey <dir>" (eg. "journey ne"). I've already incorporated a few of my common phrases that are one word (up/down/out/backwards) but I can't seem to get that to work :(

EDIT: Never mind, I got it:

local dirToLetter = {
    north = "n", n = "n",
    northwest = "(nw)", nw = "(nw)",
    west = "w", w = "w",
    southwest = "(sw)", sw = "(sw)",
    south = "s", s = "s",
    southeast = "(se)", se = "(se)",
    east = "e", e = "e",
    northeast = "(ne)", ne = "(ne)",
    up = "(up)", u = "(up)",
    down = "(down)", d = "(down)",
    out = "(out)",
    backwards = "(backwards)", bw = "(backwards)",
    journeyqn = "(journey n)",
    journeyqs = "(journey s)",
    journeyqe = "(journey e)",
    journeyqw = "(journey w)",
    journeyqne = "(journey ne)",
    journeyqnw = "(journey nw)",
    journeyqse = "(journey se)",
    journeyqsw = "(journey sw)"
}

local commands = {}
local count = 0

for line in io.lines() do

    -- only act on non-blank lines
    if string.match(line, "%S") then

        local last = commands[#commands]

         line = string.gsub(line, " ", "q")

        local letter = dirToLetter[line]

        assert(letter)

        -- first?
        if not last then
            commands[1] = {letter=letter,count=1}
        else
            -- same as previous?
            if last.letter == letter then
                last.count = last.count + 1
            else
                commands[#commands+1] = {letter=letter, count=1}
            end
        end
    end
end

for _,cmd in ipairs(commands) do
    if cmd.count > 1 then
        io.write(cmd.count)
    end
    io.write(cmd.letter, " ")
end

-- blank line
print()
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.


13,646 views.

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.