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 ➜ Lua ➜ Send command and capture output

Send command and capture output

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


Posted by Broud   Netherlands  (10 posts)  Bio
Date Fri 01 Jan 2010 12:35 PM (UTC)
Message
I'm trying to make a script that send a series of commands to the mud, and captures its consecutive output to a notepad file. I've been looking at the scripting and LUA pages, but i'm overwhelmed. I've been able to send open a notepad file, sends the commands, but how do I redirect the generated output to the notepad file? I don't know how long the output will be from the several commands. This is what I have so far:

Note "Running script."
AppendToNotepad("HEADING")
Send ("command 1 Broud")
?CAPTURE OUTPUT for 1?
Send ("command 2 Broud")
?CAPTURE OUTPUT for 2?
....
Send ("command 19 Broud")
?CAPTURE OUTPUT for 19?

I'm doing a series of 19 commands to log several items to the notepad file. So... my next question is, how do i put i a for-do loop for the commands... :)

Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 01 Jan 2010 07:36 PM (UTC)
Message
You can't directly do what you are describing, for the simple reason that the MUD server does not reply immediately to your commands. It has other players to deal with, and may send other stuff to you. For example, if you type:


inventory


You may see something like this *before* the inventory:


The guard arrives from the south.

<24hp 145m 105mv> <#21000> 

Hailiwyn chats, 'Check out what the fruit vendor is selling!'


What you really need to do is send the command, and then have a trigger that waits for the reply, the trigger being something that matches a keyword in the reply.

For example, if your inventory looks like this:


You are carrying:
     a large burlap sack
     a rusty iron sword
     some moldy cheese

<20hp 100m 100mv> <20hp 100m 100mv> 


Then the keyword might be "You are carrying:" to start an inventory list, and a completely blank line to end it.

This thread may help you:

Template:post=4957 Please see the forum thread: http://gammon.com.au/forum/?id=4957.


That shows how you can make a script that send commands, and then pauses (using triggers and coroutines) to wait for certain output. You still need to have a good idea of what the wanted lines look like.

- 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 Sat 02 Jan 2010 03:05 AM (UTC)

Amended on Tue 26 Nov 2013 03:44 AM (UTC) by Nick Gammon

Message
I have made a video showing the general idea for capturing multiple lines (and waiting for things to arrive).

More details are at:

Template:post=9965 Please see the forum thread: http://gammon.com.au/forum/?id=9965.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Broud   Netherlands  (10 posts)  Bio
Date Reply #3 on Sat 02 Jan 2010 05:08 AM (UTC)
Message
Thanks for your replies. I'll work on it with you suggestions. And happy new year :)
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.


18,944 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.