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
➜ General
➜ Zmud Convert - Can MC do [x]?
|
Zmud Convert - Can MC do [x]?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Peglegz
(4 posts) Bio
|
| Date
| Fri 17 Dec 2010 03:04 AM (UTC) |
| Message
| I'm slowly learning my way around Lua (Very. Slowly.) but there are some things not obvious to me when figuring out how to do some things I used to do in zmud.
I used to have lists of my directions, set via alias, from point A to point B - and each time I'd hit my macro to send the current direction, it'd 'pop' the first direction off the list - like so:
Directions = n,e,n,n,e,n,w,w,s,sw,in
*hit macro*
Directions = e,n,n,e,n,w,w,s,sw,in
So I could use an alias to change the value of my 'Directions' variable, and hitting the macro would execute the first direction and pop it from the list, so that the next hit of the macro does the second direction, until it runs out of directions. I preferred this method over scripting an auto walk path because it allowed me to deal with aggressive mobs or stop and talk to a friend without needing to pause anything. So, my (first) question is, how do I use lua to 'pop' that first direction off my variable? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Fri 17 Dec 2010 03:24 AM (UTC) Amended on Fri 17 Dec 2010 03:25 AM (UTC) by Nick Gammon
|
| Message
| First, let's put your directions into a table variable:
Directions = "n,e,n,n,e,n,w,w,s,sw,in"
-- populate table
dir_table = {}
for dir in string.gmatch (Directions, "%w+") do
table.insert (dir_table, dir)
end -- for
The string.gmatch pulls out "words" and puts them into the table.
Now, in your "move one direction" alias, you just pop the first entry:
-- if table not empty
if next (dir_table) then
dir = table.remove (dir_table, 1)
Send (dir) -- send to MUD
else
Note "No further directions"
end -- if
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #2 on Fri 17 Dec 2010 03:31 AM (UTC) Amended on Fri 17 Dec 2010 03:32 AM (UTC) by Nick Gammon
|
| Message
| There is actually an easier way of populating the table:
-- populate table
t = utils.split (Directions, ",")
http://www.gammon.com.au/scripts/doc.php?lua=utils.split
So your alias to remember the directions is basically a single line:
<aliases>
<alias
match="path *"
enabled="y"
send_to="12"
sequence="100"
>
<send>
dir_table = utils.split ("%1", ",")
Note ("Generated ", #dir_table, " directions")
</send>
</alias>
</aliases>
 |
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
(I added the Note to confirm it did something)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Fri 17 Dec 2010 03:34 AM (UTC) |
| Message
| Thus the popping alias could look like this:
<aliases>
<alias
match="move_once"
enabled="y"
send_to="12"
sequence="100"
>
<send>
-- if table not empty
if dir_table and next (dir_table) then
dir = table.remove (dir_table, 1)
Send (dir) -- send to MUD
else
Note "No further directions"
end -- if
</send>
</alias>
</aliases>
Now just make a macro that sends "move_once" and that will call this alias.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Fri 17 Dec 2010 03:36 AM (UTC) |
| Message
| Example output:
> path n,e,n,n,e,n,w,w,s,sw,in
Generated 11 directions
> move_once
n
You dream about moving north.
> move_once
e
You dream about moving east.
> move_once
n
You dream about moving north.
> move_once
n
You dream about moving north.
(I was asleep at the time) |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #5 on Fri 17 Dec 2010 04:59 AM (UTC) |
| Message
| You might also want to check out:
That lets you type a "speedwalk string" and have it converted. Then you could modify the alias to break up on newlines rather than commas. So for example your path might be:
path n e 2n e n 2w s (sw) (in)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | 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.
21,765 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top