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
Lavec
Newbie


Joined: 24 Mar 2010
Posts: 4

PostPosted: Wed Mar 24, 2010 5:07 pm   

String list population issues
 
Hi folks, I'm not very good at this so muddling my way through.

I'm looking to capture an outputted list from the mud automatically into a stringlist, for highlighting and use later.

The list outputs like this:
Quote:

Enemies of the Ebon Fist:
Rangor, Baldazar, Darknight, Santar, Azor, Kered, Qadaaj, Thrud, Saryn, Mendax,
Leela, Arkantos, Kakon, Teg, Erisycthon, Siena, Des, Iskla, Tekumza, Erhon,
Geraint, Enyd, Ellodin, Avice, Lachlan, Kirshbia, Avto, Trance, Caitiff, Turles,
Entaro, Kunama, Kaelai, Cliff, Akia, Silas, Thokk, Lerik, Darroth, Reid, Korlax,
Nexas, Raekwon, Bleak, Coamenel, Alban, Gaetano, Ivaldir, Dramata, Ravien,
Platonus, Kristala, Arcturus, Morthif, Hallis, Gamdian, Spudd, Laorir, Aaseth,
Inconditus, Tir, Xorot, Zhozoru, Liri, Sryn, Ephram, Hesa, Pteron, Shoshonna,
Forzt, Phae
Total: 71


I've played with this a couple of ways and the only one I have had any partial success with is:

Code:

#CLASS {tracker}
#VAR housenemies {}
#VAR tracking {0}
#TRIGGER {Enemies of the Ebon Fist:} {tracking=1}
#TRIGGER {Total: %d} {tracking=0}
#TRIGGER {(%w),} {#IF (@tracking=1) {#additem housenemies %1}}
#CLASS 0



But as you can probably see this only captures the first name on each line.

Any help would be greatly appreciated, I've seen somethings using #REPLACE but have no real understanding of how that works..

Thanks!
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Mar 24, 2010 5:53 pm   
 
1)this is a good (albeit a tad advanced) situation for a multi-state trigger. These are like several triggers chained together so that they are guaranteed to fire in order, whereas separate triggers like your example might misfire on the same line or even fire on lines you don't want them to fire on or fire in situations you don't want them to. They are a very nifty and very powerful tool, so you might want to make it a point to learn and get familiar with them.

2)There isn't any #REPLACE command, just a %replace() function. That might make for a good suggestion for CMud, though.

3)Trigger patterns only match on the first instance of the pattern text. You are trying to do a repeating loop with your pattern of (%w),, but such functionality only exists in CMud. In ZMud, if you want to loop a pattern within the same line, you have to capture the entire line and do the parsing in the script code.

Code:

#variable Clannames "the Ebon Fist|some other clan name"
#trigger "tClanEnemies" {^Enemies of ({@clannames}):$} {#if ("%1" = "the Ebon Fist") {tracking = 1} {tracking = 0};houseenemies = ""}
#condition {^(*)$} {#if (%begins(%1,"Total:")) {#state tClanEnemies 0;tracking = 0} {Houseenemies = %concat(@Houseenemies,%if(@Houseenemies,"|",""),%replace(%1,", ","|"))}} {manual}


Hopefully I didn't pile too much new stuff on you to play with, but it's not really all that complicated once you get the hang of it.
_________________
EDIT: I didn't like my old signature
Reply with quote
Lavec
Newbie


Joined: 24 Mar 2010
Posts: 4

PostPosted: Wed Mar 24, 2010 6:08 pm   
 
Thanks!

I'm going to take a look at it now.

I'm doing my best to learn what I use, so I hate just copying and pasting a script, yay, it does what I want, but I need to learn how to use it myself.

I haven't done much with the #condition so I shall have a go and see.

Again, thank you very much!
Reply with quote
Lavec
Newbie


Joined: 24 Mar 2010
Posts: 4

PostPosted: Wed Mar 24, 2010 6:51 pm   
 
Okay.

Imported and tested, it works, but it does what mine did, saves the first enemy off each line and isn't parsing the whole lot.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Mar 24, 2010 7:04 pm   
 
Whoops, missed placing double-quotes around the %1 in the replace. Without them, ZMud was using just the first three names to do the replace and totally ignoring the rest of the arguments I included. Fix that typo and things should work perfectly.
_________________
EDIT: I didn't like my old signature
Reply with quote
Lavec
Newbie


Joined: 24 Mar 2010
Posts: 4

PostPosted: Mon Mar 29, 2010 4:19 pm   
 
Sorry this took me so long to work on.

I've tweaked the code as you said and am now getting nothing

Code:

#CLASS {tracker}
#VAR clannames {the Ebon Fist}
#VAR Houseenemies {}
#TRIGGER {^Enemies of ({@clannames}):$} {#if ("%1" = "the Ebon Fist") {tracking = 1} {tracking = 0};houseenemies = "";#condition {^(*)$} {#if (%begins( %1, "Total:")) {#state tClanEnemies 0;tracking = 0} {Houseenemies = %concat( @Houseenemies, %if( @Houseenemies, "|", ""), %replace( ""%1"", ", ", "|"))}} {manual}}
#CLASS 0


I think I've put something in the trigger section in wrong. But I'm not really sure what the trigger section is doing to work it out.

Thanks!
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Mar 29, 2010 6:08 pm   
 
You did make a mistake. You rearranged the code I gave you by first creating the trigger from the #TRIGGER (probably by using the Settings Editor window or by selecting the code for the #TRIGGER and then moving that trigger to the Tracker class) and then pasting the #CONDITION in that trigger's code box. Go ahead and delete every setting in that class.

Then select everything in the code box I gave you, paste it to the commandline, press enter, and edit the resulting variable and trigger as necessary.
_________________
EDIT: I didn't like my old signature
Reply with quote
myddrun
Wanderer


Joined: 31 Mar 2005
Posts: 58

PostPosted: Tue Mar 30, 2010 6:35 am   
 
this is what I use. You should be able to modify it.

Code:
#TRIGGER "WhoStart" {INSERT YOUR STARTING PATTERN HERE} {
  #var playerlist "" "" {playerinfo}
  }
#COND {^(*)$} {#forall %subregex( "%1", "\s+|-|>|<", "|") {#additem playerlist %i}} {manual}

#TRIGGER "WhoStop" {INSERT YOUR STOPPING PATTERN HERE} {#state {WhoStart} (0)}


what the subregex is doing is replacing any "-" ">" "<" and any amount of spaces with a single "|". you could change that to spaces, and commas.
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: Fri Apr 02, 2010 1:07 pm   Solution to your problem
 
This should do what you require:

#CLASS {tracker}
#VAR clannames {the Ebon Fist}
#VAR Houseenemies {}
#TRIGGER {Enemies of @ClanNames:} {Houseenemies=%null}
#COND {!%match( %line,"Total:")} {#additem Houseenemies {%line}} {loopexp|param=15}
#COND {%match( %line,"Total:")} {#var Houseenemies {%replace( %replace( @Houseenemies, ",", ""), " ", "|")}} {exp|param=1|nocr}
#CLASS 0
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