[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Capturing and trimming a who list.

Capturing and trimming a who list.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Wed 13 Jul 2016 01:37 PM (UTC)

Amended on Wed 13 Jul 2016 04:57 PM (UTC) by Wuggly

Message
Whenever the who list is checked, the styles are recorded into a whoL table.

What I am trying to do, is right before it writes it into the mini-window, check the style.text to see what format it is in.

Whether it's like this:

Hum [ Ra:30 Th:30 Cl:30 ] Wuggly, the noob scripter.

or like this:

Elf [    God    ] Nick, the grand master.

This way I can trim off the comma and everything after so it just shows it like:

Hum [ Wa:30 Th:30 Ma:30 ] Wuggly

I'm just unsure how to go about this. Maybe something like string.find to detect the comma then gsub to cut it out?

The part I'm really confused about is when it doesn't show the class/classes and is just a word, like Demigod, God, etc.. due to those extra spaces. Then you've got two worded ones like Lesser God and Adept Finder.

Here's the code for when it writes it into the mini-winder, nothing fancy.

 if whoL ~= nil then
   local y = font_height * 2 + 35
   for i, styles in ipairs (whoL) do
     local x = 5
     for _, style in ipairs (styles) do
      x = x + WindowText (status_win, font, style.text, x, y, 0, 0, style.textcolour)
     end -- for
     y = y + font_height
   end -- for 
  end -- whoL


What's a good way to go about this?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 13 Jul 2016 08:16 PM (UTC)

Amended on Wed 13 Jul 2016 08:18 PM (UTC) by Nick Gammon

Message
Isn't this like your other question?

http://www.gammon.com.au/forum/?id=13708

Now you want to capture up to a character (the comma) rather than after it?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #2 on Fri 15 Jul 2016 08:48 AM (UTC)

Amended on Fri 15 Jul 2016 03:52 PM (UTC) by Wuggly

Message
I've tried reversing it, but just can't figure it out.

First attempt

foo = string.match (test, "(.*),.-")


Second attempt

foo = string.match (test, "(.*)%,.-")


EDIT: Finally did what I should of done a long time ago rather than bugging all of you, and researched.

...and got it to work!

foo = string.match (test, "^(.*),.-$")


Found out the .- was matching nothing until I specified the end of the line.

In case anyone is wondering where I found the info about the .-, it was here:
http://lua-users.org/wiki/PatternsTutorial

Couldn't find anything about the .- in the MUSHclient documentation.
http://www.gammon.com.au/scripts/doc.php?general=regexp
and
http://www.gammon.com.au/regexp
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sat 16 Jul 2016 09:29 AM (UTC)

Amended on Sat 16 Jul 2016 09:30 AM (UTC) by Nick Gammon

Message
Since this is a Lua pattern, not a PCRE regexp, you need to look at the documentation for string.find:

http://www.gammon.com.au/scripts/doc.php?lua=string.find

The dot matches anything, and the "-" qualifier is "zero or more, non-greedy".

Without the "$" at the end the least greedy match is nothing at all.

You can see the difference here:


print (string.find ("#hello# #world#", "(#.*#)")) --> 1 15 #hello# #world# 

print (string.find ("#hello# #world#", "(#.-#)")) --> 1 7 #hello# 


The first one uses a greedy match, so to find the closing "#" symbol it consumes everything in the string (including other "#" symbols) which is greedy.

The second one uses a non-greedy match, so it stops as soon as it can, which is the first "#" symbol.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #4 on Sat 16 Jul 2016 08:05 PM (UTC)

Amended on Sat 16 Jul 2016 08:07 PM (UTC) by Wuggly

Message
Thanks for the information.

I'm down to one last thing I can't work out and that's for names that have no commas or periods to detect right after the name.

IE:

Hum [ Ra:30 Th:30 Cl:30 ] Wuggly explores the realm.


Here's the two things I've tried.

whoT = string.match (style.text, "^(.*) %[ (.*) %] (.*?) .-$")

and the other way I simple replaced the spaces with %s
also tried without the ?

sorry im so slow when it come to regexp :/
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sun 17 Jul 2016 06:15 AM (UTC)
Message
Is the name one word?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #6 on Mon 18 Jul 2016 02:02 PM (UTC)
Message
Yes, on the server I play, names are one word.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Mon 18 Jul 2016 08:31 PM (UTC)
Message
Well, instead of searching for the comma, which may not be there anyway, search for one word.

For example: %a+

That would match one or more letters, and stop at the first space (or comma, or whatever).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #8 on Tue 19 Jul 2016 06:47 PM (UTC)

Amended on Tue 19 Jul 2016 06:59 PM (UTC) by Wuggly

Message
I've been trying, but having no luck.

This is the closest I've gotten so far to getting it.

BEFORE:
3 characters.  Total online: 5.
Ogr [ Sh: 2 Wa:30 Tg:25 ] Blake. Meat Shield
Elf [    Ra:22 Ma:24    ] Cusithe growls as she Hunts. [ShroomMinion]
Elf [ Ma:30 Wa:30 Th:30 ] Nicholai- master of lost avatars


PATTERN USED:
whoT = string.match (style.text, "^(.*) %a+ .-$")


AFTER:
3 characters. 
Ogr [ Sh: 2 Wa:30 Tg:25 ] Blake.
Elf [    Ra:22 Ma:24    ] Cusithe growls as
Elf [ Ma:30 Wa:30 Th:30 ] Nicholai- master of


Every time I try to mess with the brackets, it always gets worse. Here's one example.

BEFORE:
6 characters.  Total online: 6.
Ogr [ Sh: 2 Wa:30 Tg:25 ] Blake. Meat Shield
Hum [    Cl:28 Wa:28    ] Noah needs a shave
Elf [    Ra:22 Ma:24    ] Cusithe growls as she Hunts. [ShroomMinion]
Ogr [ Sh:26 Tg:23 Wa:26 ] Uzzi, I'm too sexy for my shirt!
Hum [ Wa:30 Tg:30 Cl:30 ] Vex Ironwolf, the Grim Warder
Elf [ Ma:30 Wa:30 Th:30 ] Nicholai- master of lost avatars


PATTERN USED:
whoT = string.match (style.text, "^(.*) %] %a+ .-$")


AFTER:
nil
nil
Hum [    Cl:28 Wa:28   
Elf [    Ra:22 Ma:24   
nil
Hum [ Wa:30 Tg:30 Cl:30
nil
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Tue 19 Jul 2016 08:10 PM (UTC)

Amended on Tue 19 Jul 2016 08:11 PM (UTC) by Nick Gammon

Message
How about this?


  whoT = string.match (line, "^(.- %] %a+)")


That matches anything, non-greedily, until it reaches a space followed by a square bracket and another space. Then it stops after the next word. Output:


Ogr [ Sh: 2 Wa:30 Tg:25 ] Blake
Hum [    Cl:28 Wa:28    ] Noah
Elf [    Ra:22 Ma:24    ] Cusithe
Ogr [ Sh:26 Tg:23 Wa:26 ] Uzzi
Hum [ Wa:30 Tg:30 Cl:30 ] Vex
Elf [ Ma:30 Wa:30 Th:30 ] Nicholai

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #10 on Wed 20 Jul 2016 12:40 AM (UTC)

Amended on Wed 20 Jul 2016 12:41 AM (UTC) by Wuggly

Message
Worked perfect, and I think I finally understand expressions a lot better now.

For example, just playing around, I found I could display it however I want it..


whoT = string.match (style.text, "^(.- %] %a+)")

-- for race
whoRa = string.match(whoT, "^(%a+ .-)")
-- for class/classes
whoCl = string.match(whoT, "^.-(%[.*%])")
-- for name
whoNa = string.match(whoT, "( %a+)$")


Huge thanks Nick!
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


23,714 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]