Help - Search - Members - Calendar
Full Version: Zmud Question
Achaea's Forums > Off-Topic > Tech Support
kazu00
Ok, I'm basically doing what Denex is for Zmud. I'm hoping to make a script that auto captures all the names from a list and stores them into a string list. However, I can't quite seem to get it work.

Oseji, Cirdan, Stardin, Leiri, Avariss, Soujirou, Alyx, Quazzi, Erika, Aes,
Emiye, Trenia, Erandac, Kentaru, Gurner, Gawi, Dalien, Dalara, Sophie, Sainen,
Ilaena, Asmodron, Aecius, Seraline, Inc, Martinet, Kagrato, Wyverex, Azaela.

I wanted to capture a grouping like that, but so far I haven't managed to get it right yet.
Sena
Are you using screenwidth 0? A script like that is much easier if you are.

With or without screenwdith 0, this trigger pattern should work:
CODE
^((?:\w+(?:, )?)+)(?:,|.)$


Now, if you do use screenwidth 0, the script would be simple:
CODE
#VARIABLE List {%replace("%1",", "|"|")}


Without screenwidth 0, it's more complicated, since you have to combine several lines into a single list. There are a few ways to do it. The easiest way is to completely clear the current variable, then append each line to it. You can clear the variable with an alias that calls the list, or by triggering a line that always precedes the list, depending on the situation. Here's an example for QW
CODE
#ALIAS qw {#VARIABLE QWList {};~qw}
#REGEX {^((?:\w+(?:, )?)+)(?:,|.)$} {#VARIABLE QWList {%if(@QWList,@QWList~|)%replace("%1",", "|"|")}}
kazu00
Sena, I tried that very last one, and it completely froze my zmud. Had to close it. I use screenwidth 80 by the way.
Sena
I just tested it, it works fine for me. The only thing I can think of is that maybe you entered #ALIAS qw {#VARIABLE QWList {};~qw} directly into the command line, and so it stripped out the ~ in ~qw. That would have caused an infinite loop.
kazu00
I've tested 5 or 6 times. Froze every time. Here's what I have:

#ALIAS qw {#VARIABLE QWList {};~qw}
#VAR QWList {}
#REGEX {^((?:\w+(?:, )?)+)(?:,|.)$} {#VARIABLE QWList {%if(@QWList,@QWList~|)%replace("%1",", "|"|")}}
Sena
Hmm. I just noticed a mistake I made in the %replace, but nothing that should cause it to freeze. %replace("%1",", "|"|") should be %replace("%1",", ","|")

If it's still not working after fixing that, I'm not sure what could be wrong.
kazu00
Just froze again, even with the change. Can you think of another way I might go about doing this?
Sena
Oh, I just realised I wasn't trying it with screenwidth 80. I changed to screenwidth 80 and tested it, it did freeze. I'll figure it out and fix it in a minute.
Sena
I think I figured out how to fix it, but I can't imagine why it had a problem in the first place... It was expecting a comma or period at the end of the line. I forgot that, with Achaea wrapping the text, sometimes the comma is moved to the next line, like this:
QUOTE
Anarwaen, Lavec, Solteria, Sahirah, Aislynn, Keneanung, Juliana, Sethai, Cosette
, Dardanus, Elaliloth, Kaelar, Mundo, Azaela, Oceana, Dalien, Branak, Aecius,

So, when it got the first line shown there, it froze. Even testing the pattern in the editor froze zMUD. But it should have simply not matched. Anyways, changing (?:,|\.) to (?:,|\.)? fixed the problem, as far as I can tell. I also forgot to escape the period in the original script, but that wasn't related to the problem.

So, replace the pattern with this:
CODE
^(?:, )?((?:\w+(?:, )?)+)(?:,|\.)?$
kazu00
Sena...you are WONDERFUL. One more question, I also can't seem to remember how to set up the regex to color a string list? How would I set this list to be a certain color?
Sena
#REGEX {\b(?:@List)\b} {#CW colour}

Replace list and colour with the variable you use and the colour you want.
kazu00
Doesn't seem to be working, it highlights the first line only.
Sena
I found another problem with the script, due to inconsistencies in the wrapping. Sometimes a space is left at the end of the line, sometimes no space is left. It's more frustrating than it should be trying to work around this.

Basically, if I have the script add a | between the existing list and the new line to add, it creates empty values in the list because sometimes the existing list already ends with |, so it results in ||. That messes up the colouring trigger. I tried using #FORALL, but that has the same problem.

If the script doesn't add the | though, it occasionally concatenates two names, when a line doesn't end with a space.

The only solution I can think of (in my drugged-up-on-allergy-medicine state) is to check to see if the string ends with a |, and if it does, remove it. Or if it doesn't, add it. As long as it's consistent.

So, the messy and inefficient script for screenwidth 80 would be:
CODE
#ALIAS qw {#VARIABLE QWList {};~qw}
#REGEX {^(?:, )?((?:\w+(?:, ?)?)+)\.?$} {#PRIORITY {#IF (@QWList) {#VARIABLE QWList {@QWList%if( %ends( @QWList, "|")=0, |)%replace( %replace( "%1", " ", ""), ",", "|")}} {#VARIABLE QWList {%replace( %replace( "%1", " ", ""), ",", "|")}}}}
#REGEX {\b(?:@QWList)\b} {#CW red}


I'm obviously going to recommend switching to screenwidth 0 now, unless it would take an insane amount of work to convert your existing scripts.
kazu00
It wouldn't but I HATE the way 0 looks.
Sena
It looks nearly identical if you set zMUD's wrapping right. The only difference is that special characters (like commas) after words are treated as part of the word, instead of being moved alone to a new line.

In preferences, under word wrap, set wrap column to 80 and wrap indent to 0. Make sure word wrap is checked, too.
kazu00
How do I alter zmud's wrapping then?
Sena
I just edited my post to include that. tongue.gif
kazu00
I'll test it tomorrow, when I don't have a 3 hour bio lab to go to. Also, if Kazu wasn't married to the world's most wonderful woman, he would shower you with flowers, gifts, and worship Sena.
Cooper
You could also just switch to screen width 0 when you run this script ^-^
Sena
QUOTE (Cooper @ Nov 3 2009, 06:39 PM) *
You could also just switch to screen width 0 when you run this script ^-^

That would work too.
CODE
#ALIAS qw {#VARIABLE QWList {};config screenwidth 0;~qw;config screenwidth 80}
#REGEX {^((?:\w+, )+\w+)\.$} {#PRIORITY {#VARIABLE QWList {%replace( "%1", ", ", "|")}}}
#REGEX {\b(?:@QWList)\b} {#CW red}

Much simpler than the previous script.
kazu00
Nevermind, I fixed by switching my screenwidth and doing what Sena suggested to the wrapping.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.