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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Changing colors problem again

Changing colors problem again

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


Posted by Lywellyn   USA  (15 posts)  [Biography] bio
Date Thu 24 Nov 2005 07:16 AM (UTC)

Amended on Thu 24 Nov 2005 07:28 PM (UTC) by Nick Gammon

Message
Using the technique you taught me in the other thread I asked about, I tried to implement a new feature, and met with little success.

Using the 'practice' command, it shows me a three column list of my currently practiced skills, in this format:


       turn undead  68%           bash door  68%              disarm  99%


What I want it to do is to color the skills less than 99% normally, but recolor skills at 99% a different color.

I set up a trigger to match such as this:


*  *% *  *% *  *%


I figured it'd put the first skill name in the first *, the first percent amount in the second *, and so on.

First off, this trigger would only fire when I used the test trigger function of the program. Using an exactly copied line from the MUD output, I tested the trigger, and it fired. But when I used the practice command and the entire list showed up, not a single one of the lines fired the trigger, not even the one I copied. I have your prompt newline plugin installed, by the way.

Secondly, when I used the test trigger for it to fire, I found out that for some reason, the asterisks I THOUGHT were storing the skill names were instead storing just a couple of spaces, and the percent asterisks ended up storing the entire block (skill name AND percent amount). So with the above example, the wildcards ended up being:


1 - "  "
2 - "     turn undead  68"
3 - "  "
4 - "       bash door  68"
5 - "  "
6 - "          disarm  99"


This isn't how I want it, as it's not going to be recolored correctly.

Any help with this matter would be most appreciated :)

Posted edited by Nick to show spacing
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 24 Nov 2005 07:40 PM (UTC)
Message
OK, you have 2 problems. The first is the wildcards not being right. That isn't totally surprising, as the "*" can match anything, including spaces. So, when you use:

* *%

It is choosing to match a couple of spaces for the first wildcard, and put the rest into the second.

To force more precise matching you want a regular expression. This matched OK for me:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="^\s*(.*?)\s+(\d+)\%\s*(.*?)\s+(\d+)\%\s*(.*?)\s+(\d+)\%\s*$"
   regexp="y"
   script="ExampleTrigger"
   sequence="100"
  >
  </trigger>
</triggers>



Output was:


Wildcards ...
1="turn undead"
2="68"
3="bash door"
4="68"
5="disarm"
6="99"
0="       turn undead  68%           bash door  68%              disarm  99%"


Your second problem is it isn't matching MUD output at all, only test output. Well, you may need to turn on "debug packets" to see why. Maybe there is a trailing space. My trigger above checks for trailing spaces so it may work without further change.

- Nick Gammon

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

Posted by Lywellyn   USA  (15 posts)  [Biography] bio
Date Reply #2 on Fri 25 Nov 2005 01:22 AM (UTC)
Message
Okay, it works *almost* perfectly. It does match, and the script I've created does recolor it like I want, but the leading spaces prior to the skill name seem to be erased...I need those leading spaces so that the skill percentages line up like normal.

What do I take out of the matching expression so that it'll match the leading spaces *and* the skill name, and put all of that into the skill wildcards (1, 3, and 5)?
[Go to top] top

Posted by Lywellyn   USA  (15 posts)  [Biography] bio
Date Reply #3 on Fri 25 Nov 2005 02:25 AM (UTC)
Message
Found out that it also matches to my skill list. Same format, except the skill names are left-aligned instead of right aligned in the columns. Any way of making the expression match both left and right align, and keep all spaces (except two spaces prior to the percent number)?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Fri 25 Nov 2005 05:14 AM (UTC)
Message
You could always just save the spaces as wildcards (eg. make it (\s*) ) and put the spaces back.

Alternatively, when displaying, format the output. For example, in Lua, you can do this:


print (string.format ("%20s", "turn undead"))

Results:

         turn undead


- Nick Gammon

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

Posted by Lywellyn   USA  (15 posts)  [Biography] bio
Date Reply #5 on Fri 25 Nov 2005 12:12 PM (UTC)
Message
I think I'm gonna need a full matching expression example again...mostly because regular expressions still confuse me. Would they be separate wildcards, or something else?

Can't use Lua, already made things in VBScript :(
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Fri 25 Nov 2005 07:41 PM (UTC)

Amended on Fri 25 Nov 2005 07:43 PM (UTC) by Nick Gammon

Message
For regular expressions, read my post:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=5089

If you use "extended" syntax (with (?x) ) you can add spaces to the regexp to make it easier to follow, like this:


(?x)^ \s* (.*?) \s+ (\d+) \% \s* (.*?) \s+ (\d+) \% \s* (.*?) \s+ (\d+) \% \s* $


There is some repetition, because you have 3 sets of skills on one line, but the important elements are:


  • (?x) - use extended syntax

  • ^ - match start of line

  • \s* - match zero or more spaces

  • (.*?) - match any text, non greedy, put into a wildcard

  • \s+ - match one or more spaces

  • (\d+) - match one or more digits, put into a wildcard

  • \% - match on the % symbol

  • (repeats twice)

  • $ - match end of line


As for Lua, you would be able to format text in VBscript one way or another. For example, counting how long the text is and adding spaces to the start as required.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


16,554 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]