Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Wizman
Newbie


Joined: 22 Jul 2006
Posts: 3

PostPosted: Mon Jul 24, 2006 11:37 am   

Capturing multiple lines
 
I have seen various posts on the subject but since I have only a little understanding of what the commands mean and how they work it is hard to make head or tail!

What I want to do is to make a trigger that activates on the text 'Characters here: ' (note the space, though for you experts it may not be important). The text that follows can be up to 20 different names each with a possibility of several different 'stances' - each of which is enclosed by () and can be separated by 1 or 2 spaces. The first stance enclosed in () is always, if it exists at all, immediately after the name - with no spaces. Each stance is separated by a single space and the last stance is separated from the next character name by two spaces. The stances available are AFK, resting, sitting, invisible, hidden, mounted upon a ... The number of names can result in them being spread across several lines.

What I want to be able to do is to extract just the names from the product in order to be able to run commands using those names.

An example (contrived) of the product is:

Characters here: Susan(hidden) (resting) John(resting) (sitting) (invisible) Freddy(hidden)
Billy(mounted upon a horse)

I currently have a series of classes that each have a single trigger to try to capture the text on the first line and are on the pattern:

#CLASS {Who's here1}
#TRIGGER {characters here: (%w)~(*~) (%w)~(*~) (%w)~(*~)} {
#T- {Who's here3}
#SHOW %1
#SHOW %2
#SHOW %3
}
#CLASS 0

The #T- {Who's here3} is designed to disable subsequent triggers that could gather some of the same information and thereby run (or disable) the commands activated by the first trigger. The #SHOW lines are just there so I can see what I am so far gathering. The trouble with this approach is that it seems circuitous and I'm sure there must be a way to simply capture all the text - however many characters and stances - and then remove anything that is in (), or even to capture only what is not in (). The only other constant with which to possibly limit the capturing is the word 'Command' which appears after each command that is executed.

Can anyone help me? I hope I have given enough of an explanation of my problem.

Thanks


Last edited by Wizman on Thu Jul 27, 2006 10:47 pm; edited 2 times in total
Reply with quote
shaun.murray
Magician


Joined: 23 Jul 2005
Posts: 334
Location: Chicago

PostPosted: Thu Jul 27, 2006 1:30 pm   
 
I'm not the greatest by any means... But I THINK what your looking for is #C+ and #C-. I don't know how you would be able to pull the information outta the capture. Maybe be able to put it into an array??? But if you want to just get that information, and put it on another screen, that would be easily done with #C... HTH's at least a little!
Reply with quote
Wizman
Newbie


Joined: 22 Jul 2006
Posts: 3

PostPosted: Thu Jul 27, 2006 10:49 pm   
 
Thanks. The #C+ helps to take the text somewhere else, but what I really want to be able to do is take only those words that are not enclosed by brackets and then to be able to run game commands on them.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Fri Jul 28, 2006 12:00 am   
 
Do you want to keep track of the status items, or no? If no, a trigger like this will work:

#trigger {Characters here: ([%w%s~(~)])} {Characters = "%1"`#forall "sitting|standing|resting|etc" {Characters = %replace(@Characters, "%i", "")}`Characters = %replace(%replace(@Characters, ") (",""),"() ","|")}

It might be off, but it should get you really close.

As for multiple lines, is it ZMud that's doing the wrapping or your game? If it's ZMud, then the above trigger will match the entire thing and you don't have to worry about multiple lines at all. If it's the game, are you able to set the wrap column? If so, set it as high as you can to prevent the game from wrapping lines. If not, then you need to use a multistate trigger and do all that processing in the last state:

#trigger {Characters here: ([%w%s~(~)])} {Characters = "%1"`#T+ tCharacters2)}
#condition {your prompt goes here} {#T- tCharacters2`#forall "sitting|standing|resting|etc" {Characters = %replace(@Characters, "%i", "")}`Characters = %replace(%replace(@Characters, ") (",""),"() ","|")} {nocr|prompt}

#trigger {([%w%s~(~)])} {Characters = %concat(@Characters,"%1")}
_________________
EDIT: I didn't like my old signature
Reply with quote
Wizman
Newbie


Joined: 22 Jul 2006
Posts: 3

PostPosted: Tue Aug 15, 2006 9:35 pm   
 
Thanks for the suggestions so far. Sorry for the delay in replying, I've been away on holiday.

I've tried the one above, by MattLofton, but I get a syntax error in the trigger when it tries to read -
{Characters = "%1"`#forall "sitting|standing|resting|etc" {Characters = %replace(@Characters, "%i", "")}`Characters = %replace(%replace(@Characters, ") (",""),"() ","|")}

Because I don't fully understand what the trigger is actually doing as it goes along I can't perform adjustments to it. I can see that the script is intended to find all instances of the "sitting|standing|resting|etc" and replace them with nothing, but I can't translate the how of it, and so can't tune it. Is it possible to enlarge your generous assistance so far?

Thanks
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Aug 15, 2006 11:01 pm   
 
oh, whoops. The MUD I use uses the ; for the SING command (that, and the mapper picks up on semicolons in the room descriptions, treating it as a separator character instead of as literal text) so I've changed it to the backwards apostrophe (the key above the TAB key with the tilde on it). Changing all of these characters to ; or whatever your actual separator character is will fix that syntax error thing.

As for explanations, let's say you have this line:

Characters here: Susan(hidden) (resting) John(resting) (sitting) (invisible) Freddy(hidden)
Billy(mounted upon a horse)

The trigger first takes everything after the colon and assigns it to a variable (character = "%1"):

Susan(hidden) (resting) John(resting) (sitting) (invisible) Freddy(hidden)
Billy(mounted upon a horse)

Next, the #forall loops through all the status labels. In each iteration of the loop, whatever the current status label is is completely erased from the @character variable via %replace(). It looks like this:

Sitting
Susan(hidden) (resting) John(resting) () (invisible) Freddy(hidden)
Billy(mounted upon a horse)

Hidden
Susan() (resting) John(resting) () (invisible) Freddy()
Billy(mounted upon a horse)

the end result of this step
Susan() () John() () () Freddy()
Billy()

Next, the parentheses are taken care of in two steps:

1)interior parentheses--) (--are removed (note: there might be a problem here with the parentheses sets not being completely removed)

Susan() John() Freddy()
Billy()

2)exterior parentheses are removed and replaced with the stringlist divider (|, or the pipe symbol). Again, there's going to be a problem regarding the last set of parentheses that I didn't take into account.

Susan|John|Freddy|Billy()

If this is what you see happening, then the fixes to above problems will be a simple matter of reorganizing the nested %replace() functions and adding new ones as needed. You should be able to figure this out, but if you get stuck we can help.
_________________
EDIT: I didn't like my old signature
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net