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
➜ how to save a block of information
how to save a block of information
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Silencher
(55 posts) Bio
|
Date
| Thu 10 Apr 2014 04:30 AM (UTC) |
Message
| In one mud I play there's a bank of sorts where you can store items. You can only view the items in the bank when you're at the bank, which while realistic is inconvenient.
I want to effectively 'save' everything and then make an alias to reproduce what was 'saved' in my output, and each time I look at my bank inventory, I'll delete/save over my old values so it's always current as of the last time I checked my bank.
Can I get a step by step way of how to do this, as if I have no programming/scripting experience please?
Below is a sample of the output I want to save/be able to re-print later.
--
> There are n items stored in this vault:
Item one.
Item two.
Item three.
The current weight in the vault is: n
The maximum amount this vault can hold is: n in weight.
--
I was thinking of putting * wherever there is an 'n' and using %1, %2, etc. to save those, but how would I deal with the 'items', especially since there could be no items or up to dozens of different items?
I hope someone can help, and again, if you could tell me how to do this as if I have no knowledge, that would be best. I'm really a fairly basic user of scripting. | Top |
|
Posted by
| hogarius
USA (22 posts) Bio
|
Date
| Reply #1 on Sun 13 Apr 2014 01:52 AM (UTC) Amended on Sun 13 Apr 2014 02:16 AM (UTC) by hogarius
|
Message
| Since you want to wait for some incoming text and respond to that text, and then immediately wait for additional incoming text and respond to that text, and do that several times, you want to use MUSHclient's "wait" module. The first line of the script in the trigger below is 'require "wait", which loads the wait module into MUSHclient and makes it available for use.
The trigger below is based on the text you said the mud sent when you view the items in the bank. I've added some comments to explain what the lines of the script do. (Comments in Lua begin with "--" .) Read through the script line by line to see what it does.
<triggers>
<trigger
enabled="y"
match="There are (\d+?) items stored in this vault\:"
name="vault_items"
regexp="y"
send_to="12"
sequence="100"
>
<send>
require "wait"
stuff = {} --creates an empty table that will list the items in the vault
count = ("%1") --sets the count variable to the value captured in the 1st set of parentheses in the trigger pattern.
function trackStuff()
wait.regexp("^$") -- waits for a blank line
for i = 1, count do -- perform the next block (count) times
stuff[i] = wait.regexp("^(.*?)$") -- waits for a line of input from the mud and sets the value of the iTH item of the stuff array to that line
end -- for i = 1, count
wait.regexp("^$") --waits for a blank line
weight = wait.regexp("(.*?)") --waits for the line that gives the current weight and sets the value of the weight variable to that line.
maxW = wait.regexp("(.*?)") --waits for the line that gives the maximum weight and sets the value of the maxW variable to that line.
end -- function trackStuff()
wait.make (trackStuff) --passes the trackStuff function defined above to the wait module to be executed
</send>
</trigger>
</triggers>
After you look in the vault, you can display the contents of the vault again by loading the following alias into your MUSHclient world. Type "showvault" (without the quotes) in your command line to run the alias.
<aliases>
<alias
name="showvault"
match="showvault"
enabled="y"
send_to="12"
sequence="100"
>
<send>Note("showvault")
Note("")
Note("There are " .. count .. " items stored in the vault.")
Note("")
for i = 1, count do --execute the following command (count) times)
Note(stuff[i]) --display the iTH item of the stuff array
end --for i = 1, count
Note("")
Note(weight) --displays the line of text currently in the weight variable
Note(maxW) --displays the line of text currently in the maxW variable
</send>
</alias>
</aliases>
To test the trigger and alias, I used MUSHclient's "Debug simulated world input" dialog box. I pressed Ctrl-Shift-F12 and typed in several variants of the text below and sent it to be processed by the trigger. I then typed "showvault" (without the quotes) into the MUSHclient command line to see the information displayed on the screen.
There are 3 items stored in this vault:
an American idol
a tennis racket
a glob of mud
The current weight in the vault is: 42
The maximum amount this vault can hold is: 75 in weight.
I'm sure you'll need to step through the trigger and alias and tweak it to meet your needs. But this should help get you started. | Top |
|
Posted by
| Silencher
(55 posts) Bio
|
Date
| Reply #2 on Sun 13 Apr 2014 02:33 AM (UTC) Amended on Sun 13 Apr 2014 02:39 AM (UTC) by Silencher
|
Message
| Here's what I see when I type 'list'(pretend the --'s don't exist)
--
There are 97 items stored in this vault:
Two items.
Ninety two items.
item.
Two items.
The current weight in the vault is: n
The maximum amount this vault can hold is: n in weight.
>
--
I cut and pasted your code exactly and made no changes,
here is the output when I type 'showvault': (again pretend the --'s aren't there, and all of this is exact, including the blank lines.
--
showvault
There are 97 items stored in the vault.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
nil
nil
--
I'm not sure how to fix this. I think I need to alter these two pieces of your trigger's code:
--
weight = wait.regexp("(.*?)") --waits for the line that
maxW = wait.regexp("(.*?)") --waits for the line that
--
But I'm not sure how, should I enter the following lines
--
The current weight in the vault is: n
The maximum amount this vault can hold is: n in weight.
--
Like this? :
--
weight = wait.regexp("The current weight in the vault is: (.*?)")
--
Also, in the 'for' loop, does it automatically do i++? I don't see anything like that but I haven't seen for loops used in Lua before. I thought that might be why the trigger isn't working. Here's your code:
--
for i = 1, count do -- perform the next block (count)
times
stuff = wait.regexp("^(.*?)$") -- waits for a line of
input from the mud and sets the value of the iTH item of the stuff array to that line
end -- for i = 1, count
--
I appreciate the help, I'm not sure if my example was messed up or if there might be something minor in the trigger itself or what.
EDIT: Also - would it be possible for the 'max weight' line to be where it ends, and for the for loop to somehow stop at the 'current weight' line, rather than for the number of items? As you can see from my example, this mud 'clumps' the items together, so there may be 98 items but not 98 lines of text. I could set up separate triggers to capture the current/max weights in other triggers, that would be referenced in the 'showvault' alias.
I know this is a lot of trouble, but it might make the for loop issue easier to solve, possibly? Not sure. | Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sun 13 Apr 2014 04:17 AM (UTC) |
Message
|
Quote:
Below is a sample of the output I want to save/be able to re-print later.
--
> There are n items stored in this vault:
Item one.
Item two.
Item three.
The current weight in the vault is: n
The maximum amount this vault can hold is: n in weight.
--
Can you copy and paste actual output? This looks like made-up data. For example, it wouldn't say "n items".
For example, here:
There are 97 items stored in this vault:
Two items.
Ninety two items.
item.
Two items.
The current weight in the vault is: n
The maximum amount this vault can hold is: n in weight.
>
I don't see 97 lines of items. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Silencher
(55 posts) Bio
|
Date
| Reply #4 on Sun 13 Apr 2014 04:52 AM (UTC) Amended on Sun 13 Apr 2014 04:58 AM (UTC) by Silencher
|
Message
| The second block(cut and pasted below) you quoted is more or less the right output. The mud itself clumps the items. If you add the items in this block there are 97 items, but not 97 lines.
--
There are 97 items stored in this vault:
Two items.
Ninety two items.
item.
Two items.
The current weight in the vault is: n
The maximum amount this vault can hold is: n in weight.
>
--
So above, it's 2+92+1+2 = 97 items total.
In this mud if you have 3 red apples it's
--
Three red apples.
--
Not
--
red apple
red apple
red apple
--
The example I originally posted at the start of this thread wasn't accurate, but the block above with the 97 items is an example of the actual output, including spaces/etc.
I was more going for concept in my original post, sorry about that. But the second block in your post is correct, just assume 'item/items' is anything, like 'n'. | Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #5 on Sun 13 Apr 2014 05:57 AM (UTC) |
Message
| Well in that case Hogarius' solution won't work because he expected to get 97 lines:
for i = 1, count do -- perform the next block (count) times
stuff[i] = wait.regexp("^(.*?)$") -- waits for a line of input from the mud and sets the value of the iTH item of the stuff array to that line
end -- for i = 1, count
I think you are better off looking at:
Rather than counting lines, look for a reliable start and end delimiter. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sun 13 Apr 2014 09:04 PM (UTC) |
Message
|
Silencher said:
In one mud I play there's a bank of sorts where you can store items. You can only view the items in the bank when you're at the bank, which while realistic is inconvenient.
I want to effectively 'save' everything and then make an alias to reproduce what was 'saved' in my output, and each time I look at my bank inventory, I'll delete/save over my old values so it's always current as of the last time I checked my bank.
This is almost exactly what I cover in this tutorial:
http://www.gammon.com.au/forum/?id=9965
That saves your inventory in a window which you can view at any time. The same thing would apply to your bank. |
- 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.
24,997 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top