Hajamin2005-11-09 06:10:02
Ok, I need a script that will parse out a list like this:
name, name, name, name, name, name, name, name, name, name,
name, name, name, name, name, name, name, name, name, name,
name, name, name, name
Total: 24
and using #additem place all those names into a variable.
name, name, name, name, name, name, name, name, name, name,
name, name, name, name, name, name, name, name, name, name,
name, name, name, name
Total: 24
and using #additem place all those names into a variable.
Daganev2005-11-09 06:11:32
Question.. are there always 10 names per row on qwho?
Hajamin2005-11-09 06:15:44
No, that would be the hard part... the number of names on each line is based off how your wraplength. Only thing that holds true is, the end of each line always ends in a , expect for the last one... unless the last one is the first one.
Daganev2005-11-09 06:18:12
Do you always see your name at the end of QWHO like the rest of us?
Hajamin2005-11-09 06:19:01
Yes, but that's not the QW list, or what I'm trying to parse out. It's the ORDER ENEMIES list actually.
It always ends with Total: * on a new line.
It always ends with Total: * on a new line.
Daganev2005-11-09 06:22:34
I'm not sure what your trying to do, but sometimes things are easier to do manually.
Meaning if you just made a stringlist database, you could copy and paste the list into word, then do a Find/replace for ", " with "|" and then paste that back into your zmud variable.
Thats what I did for coloring all my enemies a certain color and it tooks me 20 seconds to do it everyday... if that. (And that was dealing with 1,024 names, when I was coloring all Mag citizens)
edit: Just to make more sense, if you have a database variable like @orderenemies then you can do things to that list with a script and each one will be treated indivdual as array items.
Meaning if you just made a stringlist database, you could copy and paste the list into word, then do a Find/replace for ", " with "|" and then paste that back into your zmud variable.
Thats what I did for coloring all my enemies a certain color and it tooks me 20 seconds to do it everyday... if that. (And that was dealing with 1,024 names, when I was coloring all Mag citizens)
edit: Just to make more sense, if you have a database variable like @orderenemies then you can do things to that list with a script and each one will be treated indivdual as array items.
Sylphas2005-11-09 09:19:43
I've done it, let me see if I still have it.
I'm sure another way to do is to just grab everything up to a prompt, concatanate the strings together, and then parse based on commas. It would be slow for a huge list, but it's what I capture my messages with, and it's not noticably slow for a long message.
I'm sure another way to do is to just grab everything up to a prompt, concatanate the strings together, and then parse based on commas. It would be slow for a huge list, but it's what I capture my messages with, and it's not noticably slow for a long message.
Gwylifar2005-11-09 14:38:14
CODE
#CLASS {Utilities}
#ALIAS getcnames {#if (%1 == done) {#t- "GetCnamesTriggers"} {ScratchVar = %1;#var %1 "";#t+ "GetCnamesTriggers";%-2}}
#CLASS 0
#CLASS {Utilities|GetCnamesTriggers}
#TRIGGER "tGetCnames1" {^(%w), (*)$} {#if (%left( @ScratchVar, 1)=l and %len( %trim( %1))<>0) {#additem @ScratchVar %trim( %1);#forall {%replace( %replace( "%2", ", ", "|"), ",", "")} {#if (%len( %trim( %i))<>0) {#additem @ScratchVar %i}}}}
#TRIGGER "tGetCnames2" {(%w)$Total: %d$} {#if (%left( @ScratchVar, 1)=l and %len( %trim( %1))<>0) {#additem @ScratchVar %1};getcnames done}
#TRIGGER "tGetCnames3" {^, (%w), (*)$} {#if (%left( @ScratchVar, 1)=l and %len( %trim( %1))<>0) {#additem @ScratchVar %trim( %1);#forall {%replace( %replace( "%2", ", ", "|"), ",", "")} {#if (%len( %trim( %i))<>0) {#additem @ScratchVar %i}}}}
#CLASS 0
To use:
getcnames ListVariableName command to capture
Note that, because of a failsafe I put in to prevent me from typing this wrong and screwing up valuable information, the first character of the list variable name has to be "l" (the letter ell) for this to work. It'd be easy to take out or change this failsafe; I leave that as an exercise for the reader.
If you don't have a variable named ScratchVar, one will appear after you run this.
e.g.,
getcnames lOrderEnemies order enemies
getcnames lGuildEnemies guild enemies
getcnames lCommuneEnemies communeenemies
Note: if you want to run several like I showed above, space them out by five seconds or so. For instance:
#alarm {+5} {getcnames lGuildEnemies guild enemies}
#alarm {+10} {getcnames lOrderEnemies order enemies}
getcnames lCommuneEnemies communeenemies
That'll be $5 please. You can PayPal it to me.
Narsrim2005-11-09 15:33:39
Yay for people who can do this. He asked me first to which my first five attempts failed and I said, screw it
Ixchilgal2005-11-15 09:35:10
I've got a method to do it for my enemy lists on my Demesne script. It ain't pretty, and it's a bit slow, but it works. I need to work on cleaning it up in a big way.
Unknown2005-11-15 09:51:42
QUOTE(Narsrim @ Nov 9 2005, 04:33 PM)
Yay for people who can do this. He asked me first to which my first five attempts failed and I said, screw it
220396
Now I know where he got that script from. Yes I'm slow.
Unknown2005-11-15 10:04:35
Using a regular expression you can do it in one trigger:
^(+?|,)((?: +(?:,|\\.)?)*)?( +?)?\\s*$
Returns three matches, containing the first name in the string, all names between the first and the last, and the last name in the string, respectively. If there's just one name on the line, then matches 2 and 3 will be empty.
^(+?|,)((?: +(?:,|\\.)?)*)?( +?)?\\s*$
Returns three matches, containing the first name in the string, all names between the first and the last, and the last name in the string, respectively. If there's just one name on the line, then matches 2 and 3 will be empty.
Gwylifar2005-11-15 13:43:55
That's actually the approach I started with, and it ended up easier and quicker to do it in three triggers.
Unknown2005-11-15 14:12:31
You should ask Zugg for a function that splits strings around a delimiter. With that thing this task is really just a one-liner: split the entire matched string at commas and remove the period if necessary, and you have a list ready to be saved or done whatever with.
Gwylifar2005-11-15 15:27:00
You can do that with a two-function combination of %replace() and %expandlist() already.
Sylphas2005-11-15 22:27:52
Pretty sure it exists already, but I haven't poked around in a while.
Unknown2006-01-30 21:09:35
(I know I'm resurrecting a fairly dead thread, so blame Gwylifar for pointing me to it. I answered a similar question on the Achaea Forums recently, so sharing here, too.)
I made a trigger to capture names of enemies to my city in Achaea, and it's very similar to QW/BW in that it's just a comma-delimited list of names on the list. It loops over all the rows and concatenates each line onto a single string. At the end, it uses %subregex to replace all commas and/or spaces with a list separator, thus turning it into a list of names with one trigger and one function call and one variable. Capturing the text is still quite slow, I admit, but it's not something I do often, so I can live with it. I sure wish Zugg would make everything easy for us, instead of always having to work for even the simple things.
I made a trigger to capture names of enemies to my city in Achaea, and it's very similar to QW/BW in that it's just a comma-delimited list of names on the list. It loops over all the rows and concatenates each line onto a single string. At the end, it uses %subregex to replace all commas and/or spaces with a list separator, thus turning it into a list of names with one trigger and one function call and one variable. Capturing the text is still quite slow, I admit, but it's not something I do often, so I can live with it. I sure wish Zugg would make everything easy for us, instead of always having to work for even the simple things.
Unknown2006-01-31 01:00:22
So long as you're reviving this old thread, I have another related (somewhat) question.
I captured all of my guild and commune enemies to a variable easily enough, but now I'm having trouble coloring them. I pretty much just did this:
#TRIGGER (%w) {#if (%ismember( %1, guildEnemies)) {#CW red}}
For some reason, though, it keeps coloring the entire line instead of only the matching text. It works correctly if, instead of the #CW, I use #CO {%1} red, but then it creates a trigger for each individual person.
I just noticed also that it doesn't color the full line in every case. For example, in my GUILD ENEMIES list, the commas are still white. If one of my enemies is in the room though, it colors the full action they take instead of just their name.
Any suggestions what I'm missing?
I captured all of my guild and commune enemies to a variable easily enough, but now I'm having trouble coloring them. I pretty much just did this:
#TRIGGER (%w) {#if (%ismember( %1, guildEnemies)) {#CW red}}
For some reason, though, it keeps coloring the entire line instead of only the matching text. It works correctly if, instead of the #CW, I use #CO {%1} red, but then it creates a trigger for each individual person.
I just noticed also that it doesn't color the full line in every case. For example, in my GUILD ENEMIES list, the commas are still white. If one of my enemies is in the room though, it colors the full action they take instead of just their name.
Any suggestions what I'm missing?
Unknown2006-01-31 06:40:54
Store the names in a string in the format: "Name1|Name2|Name3|NameN". The colouring trigger should then just be:
#REGEX {(\\b@guildEnemies\\b)} {#CW red}
#CW, quote from docs: "will color the phrase matched by the trigger with the specified color." The key word being "matched". Your trigger matches the whole line, so that's what is being coloured. The trigger above only matches a single word in a line if that word is contained in your string list, so only that one word is coloured.
#REGEX {(\\b@guildEnemies\\b)} {#CW red}
#CW, quote from docs: "will color the phrase matched by the trigger with the specified color." The key word being "matched". Your trigger matches the whole line, so that's what is being coloured. The trigger above only matches a single word in a line if that word is contained in your string list, so only that one word is coloured.
Asarnil2006-01-31 09:10:18
or an even easier way to do it
#trigger {%q{@GuildEnemies}%q} {#cw red}
#trigger {%q{@GuildEnemies}%q} {#cw red}