|
myrison Beginner
Joined: 10 Nov 2006 Posts: 22
|
Posted: Tue Mar 27, 2007 4:30 pm
Storing multiline output with commas to a string list |
Hi all... after two hours of hair-pulling, I am turning to the experts for help.
My MUD outputs the following text to tell you whom you have previously met. I would like to store these names into a stringlist with the names as separate entries to utilize them in other ways.
Quote: |
These are the people you remember:
Joe, Sally, Bob, Nate,
Jim, George, Jason, (etc)
Your brain can handle forty-eight more names.
|
The number of lines to capture will vary as you know more or less people, so I have set up a trigger class to turn on after the first line (these are the people you remember...), and to turn off on the last line (your brain can handle...), and to capture everything else inbetween using a trigger. However, I cannot seem to find a way to capture everything in between in a way that removes the commas and stores the names separately into one stringlist.
I'm guessing there is an easy solution that I am overlooking and I would be grateful if someone can point me in the right direction. I will hold off posting my code here for now as I feel I'm going in the wrong direction with it and starting from scratch is probably best.
Thanks in advance. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Mar 27, 2007 5:24 pm |
Hmm... How about this?
#var NameList ""
#trig {These are the people you remember:} {#t+ NameCap;#var NameList ""}
#cond {Your brain can handle * more names.} {#t- NameCap}
#trig "NameCap" {^(*)$} {#additem NameList %replace(%replace(%1,",")," ","|")}
I had to use two separate %replace functions instead of a since %replace(%1,", ","|") because at the end of the line, the comma might not be followed by a space and you won't want that comma replacing with a pipe anyway. You might want to add a %trim around %1 as well if there's an extra space at the end of the line that's being converted into a pipe and giving you two pipes in a row with no value between. |
|
|
|
myrison Beginner
Joined: 10 Nov 2006 Posts: 22
|
Posted: Tue Mar 27, 2007 7:19 pm |
Thank you for the help. Your code looks similar to my efforts as well, and it appears the commas in the lists of names are creating problems with the parsing. Using your code, it starts by capturing the "These are the people you remember" line and parsing it into These|are|the (etc.) as the first strings in the variable.
I was able to bypass that by skipping the first line in the trigger, but even when I do that, the trigger captures only up the the first name in each line (something to do with the commas). So, in the example above, it is only capturing two strings into the variable (Joe|Jim). After it hits the first comma in each line it stops.
I attempted to bypass this as well by using quotes around the %1, as follows:
replace( %replace( "%1", ","), " ", "|")
When I do this, however, the entire line is stored as the first string in the stringlist, example:
item 1) Joe|Sally|Bob|Nate
item 2) Jim|George|Jason
Also note there is no extra space at the end of the string lists.
Any further ideas would be much appreciated! If there is more information you need to work it out, please let me know. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Mar 27, 2007 7:57 pm |
Strange, that's worked when I've tried it in other applications. That's quite vexing. The other thing you could try is using %match or %regex with a pattern of (%w), or (\w+), and then saving the results.
|
|
|
|
myrison Beginner
Joined: 10 Nov 2006 Posts: 22
|
Posted: Tue Mar 27, 2007 8:17 pm |
I suppose it is somewhat comforting that I wasn't missing anything overly simple, but that doesn't make it any less frustrating. Thanks for your continued help. Here is some more information that maybe will help someone figure out what might be going wrong in the code. Instead of worrying about the triggered text for now, I am just focusing on adding information to the variables to make sure that part is happening correctly (and it is not).
Using this:
Code: |
#var remember_namelist %replace( "Akthar, Alexi, Alorrana, Altar, Argor, Arien", ", ", "|")
|
works just fine, and adds the names to the var just as desired in a stringlist format.
However, when using #additem after adding the initial information to add additional names to the stringlist, problems begin to develop:
Code: |
#additem remember_namelist {%replace( "Tarax, Tletlcoloti, Totty, Tuz, Wulfgang", ", ", "|")|}
|
When this is used to add additional items to the stringlist, all of the first entries remain fine, but everything added in this step is added as one entry in the stringlist, separated by the pipe symbols. Example: Tarax|Tletlcoloti|Totty|Tuz as one entry in the stringlist.
If the limitation is indeed limited to the #additem function, does anyone have alternative ideas? I will try the suggestions related to %regex and %match, but neither is overly familiar to me, so I'm not sure if I'll get that to work.
Thank you. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Mar 27, 2007 8:37 pm |
Well, one simple workaround you could use is something like this:
#trig "NameCap" {^(*)$} {#forall %replace(%replace(%1,",")," ","|") {#additem NameList %i}}
Not very neat, but it should work. |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Tue Mar 27, 2007 8:46 pm |
Code: |
#SHOW %concat("Joe|Mike|Bobby","|",%subchar("Akthar, Alexi, Alorrana, Altar, Argor, Arien.",", .","|")) |
Code: |
#var names {"Joe|Mike|Bobby"}
#var names {%concat(@names,"|",%subchar("Akthar, Alexi, Alorrana, Altar, Argor, Arien.",", .","|"))}
#show @names |
|
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
myrison Beginner
Joined: 10 Nov 2006 Posts: 22
|
Posted: Tue Mar 27, 2007 9:01 pm |
Fang Xianfu wrote: |
Well, one simple workaround you could use is something like this:
#trig "NameCap" {^(*)$} {#forall %replace(%replace(%1,",")," ","|") {#additem NameList %i}}
Not very neat, but it should work. |
Strangely, this adds only the first item in each line to the stringlist as well. As soon as it hits a comma, it balks and skips to the next line.
If I replace %1 with "%1" in your code, it works better, but captures only every other line of output into the stringlist (which is the closest anything has come yet - and definitely seems to be on the right track). If anyone can see why only every other line of output would be captured using this code, I am all ears. |
|
Last edited by myrison on Tue Mar 27, 2007 9:41 pm; edited 1 time in total |
|
|
|
myrison Beginner
Joined: 10 Nov 2006 Posts: 22
|
Posted: Tue Mar 27, 2007 9:35 pm |
Arminas wrote: |
Code: |
#SHOW %concat("Joe|Mike|Bobby","|",%subchar("Akthar, Alexi, Alorrana, Altar, Argor, Arien.",", .","|")) |
Code: |
#var names {"Joe|Mike|Bobby"}
#var names {%concat(@names,"|",%subchar("Akthar, Alexi, Alorrana, Altar, Argor, Arien.",", .","|"))}
#show @names |
|
Arminas, what you posted does not seem to work, or I cannot take what you have written and translate it successfully into the case I am working with. Instead of dealing with fixed strings like you have used, I am relying on multiple lines of output from the mud to generate the variables, which unfortunately seems to complicate things significantly.
here is how I have attempted to copy what you provided, and it unfortunately did not work... (which may well have been my own lack of understanding of what you were trying to suggest):
Code: |
#TRIGGER {^(*)$} {
#var remember_namelist %1
#VAR remember_namelist {%concat( @remember_namelist, "|", %subchar( %1, ", ", "|"))}
#show @remember_namelist
}
|
If you could further clarify what you had in mind and if you believe it will work with this case I would be very appreciative. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Mar 27, 2007 10:19 pm |
I was still in CMUD mode - zMud likes it better if you surround your %1 in quotes if it contains spaces.
As for Arminas' example, simply remove the first #var line. The second line should successfully append the new line to the variable. |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Tue Mar 27, 2007 10:23 pm |
Lol, OUCH! I was trying to show you the concept, not suggesting that you place the code as is within the trigger. Here is what you want.
Code: |
#TRIGGER {These are the people you remember:} {#t+ NameCap;#t+ NameCon;#var remember_namelist ""}
#TRIGGER "NameCon" {Your brain can handle * more names.} {#t- NameCap;#t- NameCon} "" {disable}
#TRIGGER "NameCap" {^(*)$} {#if (%pos( "are the", "%1")>1) {#abort 1};#VAR remember_namelist {%concat( @remember_namelist, %subchar( "%1", ", ", "|"))}} "" {disable} |
|
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
myrison Beginner
Joined: 10 Nov 2006 Posts: 22
|
Posted: Wed Mar 28, 2007 2:26 am |
Arminas, thank you for the update. I grasped what you were pointing at before, but obviously not completely. I now see what you are trying to do, and the updated code did the trick.
Thanks to you both for haning through me with this! I've yet to find a way to stump the group here, and thought I might have found the question that was going to do it today. I'll have to keep trying. Fang Xianfu, thanks for your help as well. Much appreciated. |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Wed Mar 28, 2007 3:27 am |
myrison wrote: |
With your code, because you are using the #var command to populate @remember_namelist, and that the trigger fires on every line that includes names, the values populated in the variable are deleted and replaced with the subsequent values each time a new line is received until the text is received that disables the trigger.
|
Urm, I didn't just think hey this should work. I tested this before posting it. On Zmud no less... I even opened a new blank session pasted it into the command line and hit enter. Then I tested it again.
I suggest that you create a new session paste my solution all at once into the command line and hit enter then try it out. Without all of your other settings it might just work. If it STILL fails then paste some actual data from your mud so we can see what is wrong.
Edit: Ha! you beat me to posting the reply. Glad to help. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
myrison Beginner
Joined: 10 Nov 2006 Posts: 22
|
Posted: Wed Mar 28, 2007 10:37 pm |
Sorry about that, my Zmud went a little haywire on me the first time and when I quit out of it and started anew with the code you posted it worked like a charm. Again, the assistance is very very much appreciated. Thanks again for the help!
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|