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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Triggers and part-line colours

Triggers and part-line colours

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


Posted by Tiopon   USA  (71 posts)  [Biography] bio
Date Thu 13 Oct 2005 05:28 PM (UTC)
Message
Checking to see if it's possible to match a trigger to a partial-line colour/highlighting. For example, if the line has:
left right front back
having it realize that 'front' was the option that it wants to pull out of the line, without needing to make multiple triggers involving all the varied possibilities. Part of a disagreement about client capabilities and all. :) Did a quick search, but most results seem to be regarding making the matching work in the first place for whole-line selections. Anyways, thanks for the time and the excellent client.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #1 on Thu 13 Oct 2005 07:04 PM (UTC)
Message
You just want to match 'front'?

Make a new trigger, make 'front' the match text, check the regular expression button (and ignore case, if you want it), and then set a color to highlight.

Or did you want it to highlight the third item? or something else entirely?

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Tiopon   USA  (71 posts)  [Biography] bio
Date Reply #2 on Thu 13 Oct 2005 07:28 PM (UTC)

Amended on Thu 13 Oct 2005 07:50 PM (UTC) by Tiopon

Message
I want to match whichever word is in bold. Whether this word is front, back, the first or the third in the string... If this means making 4 triggers to match this, so be it. But the goal is that I want to catch whichever word is in bold and return said word back through the client, wherever that bold word happened to be.

The idea is that if I have to do 4 triggers and have:
%s %s %s %s
%s %s %s %s
%s %s %s %s
%s %s %s %s
that at least works... But I can't tell if there's any way to match a bold phrase inside a trigger, or if it's only possible to match it when the entire phrase is bolded.
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 13 Oct 2005 09:33 PM (UTC)

Amended on Thu 13 Oct 2005 09:36 PM (UTC) by Nick Gammon

Message
I gather you want to match on 4 words, one of which might be in bold, and report which one that is? The words may or may not be exactly "left right front back"?

First, normal trigger matching lets you specify the colour, boldness etc. of the match text, but that only applies to the first matching character.

It would be OK if you wanted to find "front" in bold, wherever it is on the line, but I gather you are looking for something slightly different.

First, let's explore what you can do with a trigger and calling a script in Lua.

If this is your trigger:


<triggers>
  <trigger
   custom_colour="4"
   enabled="y"
   match="left right front back"
   name="testtrigger"
   script="MatchBold"
   sequence="100"
  >
  </trigger>
</triggers>


Then you can write a small script to show what is being received:


function tprint (t, indent, done)
  done = done or {}
  indent = indent or 0
  for key, value in pairs (t) do
    Tell (string.rep (" ", indent)) -- indent it
    if type (value) == "table" and not done [value] then
      done [value] = true
      Note (tostring (key), ":");
      tprint (value, indent + 2, done)
    else
      Tell (tostring (key), "=")
      print (value)
    end
  end
end


function MatchBold  (thename, theoutput, wildcards, line)
  Note ("Trigger " .. thename .. " fired.")
  Note ("Matching line was: " .. theoutput)
  Note ("Wildcards ...")
  table.foreach (wildcards, print)
  Note ("Style runs ...")
  tprint (line)
end -- of MatchBold  




The "tprint" function recursively displays entries in a Lua table, and is supplied as part of the MUSHclient distribution in the exampscript.lua file.

Testing this with the word "front" in bold gives this result:


Trigger testtrigger fired.
Matching line was: left right front back
Wildcards ...
0=left right front back
Style runs ...
1:
  textcolour=12632256
  backcolour=0
  length=11
  style=0
  text=left right 
2:
  textcolour=16777215
  backcolour=0
  length=5
  style=1
  text=front
3:
  textcolour=12632256
  backcolour=0
  length=5
  style=0
  text= back


This gives us a big clue as to what we need to do to report the word in bold, walk through the table and find the entry with a style of 1 (the bold bit). Of course, we can do other tests too, like testing the foreground/background colour, and other style bits. For reference, style bits are (bold=1, underline=2, blink=4) or'ed together (eg. bold underline would be 6).

Now we can simply check in a loop for which line entry is the bold one, by replacing the script function called with this one:



function MatchBold  (thename, theoutput, wildcards, line)
 
  for k, v in pairs (line) do
    if v.style == 1 then
      Note ("Bold word is " .. v.text)
    end -- if
  end -- for
 
end -- of MatchBold  



Running this on my test line gives:


Bold word is front


Of course, if you want to match other words, then simply modify the trigger accordingly, the script will stay the same.

The beauty of this approach is that by scripting, you can identify words that match a tight criteria (eg. red bold italic), and throw in other tests as well (eg. displaying the words that do not match as well).






- Nick Gammon

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

Posted by Tiopon   USA  (71 posts)  [Biography] bio
Date Reply #4 on Thu 13 Oct 2005 09:39 PM (UTC)
Message
Thanks for the speedy response. :) I'll refer the nay-sayers to this to prove that at least this excellent client is able to catch the more difficult scripting issues.
[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,292 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]