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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Additional help with replace trigger
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Additional help with replace trigger

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


Posted by Sachi   USA  (1 post)  [Biography] bio
Date Sun 15 May 2016 07:13 PM (UTC)
Message
While searching for a trigger to replace the output of one string with another (while omitting the original), I came across http://www.gammon.com.au/forum/?id=12083 . This was exactly what I needed!

It was mentioned in this thread that there was a method to have the resulting output displayed in the original color rather than the note color, and this is why I am back again.

The trigger I copied from that linked thread does work wonderfully but I was wondering how one goes about achieving the original output color as mentioned therein. Is this an incredibly complicated process or is it something that even a complete novice would be able to pull off?

Thank you in advance for any help that might be provided!
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Sun 15 May 2016 07:30 PM (UTC)

Amended on Sun 15 May 2016 07:43 PM (UTC) by Fiendish

Message
Quote:
Is this an incredibly complicated process

Relatively speaking, yes. [1]

Quote:
or is it something that even a complete novice would be able to pull off?

No. :\ [2]

Output substitution has always been a 2nd, maybe 3rd, 4th, or 5th class citizen for MUSHclient.
You can sort of do it, but doing it well is definitely not easy.

[1] - Actually, I know of two and a half ways to do this. 1.5 ways are very complicated and also do not work at all on GMCP. They involve a big song and dance of figuring out where to do your substitution on some data structures that hold chunks of text and color information, and then recombining the old colors with the new text for printing. The other way works also on GMCP and is significantly less complicated, but is simultaneously more obscure because it uses OnPluginPacketReceived instead of triggers and less obscure because it doesn't care about color style runs which for all I know aren't actually documented anywhere. All 2.5 ways require special extra extra effort if you want to match text across color boundaries.

Somewhat annoyingly, also, because there's no simple single built in "Substitute" function, you can't sanely do this with basic triggers. Realistically you need to make a plugin that both handles the logic of substitution and also the management of what to substitute for what.

For Aardwolf I've chosen to go with the one that works on GMCP using OnPluginPacketReceived instead of triggers, because Aardwolf sends player communication messages over GMCP.

[2] - Not without someone else already having done a bunch of work already for you and then digging around to find this post on the forum.

You can take a look at my plugin here:
https://raw.githubusercontent.com/fiendish/aardwolfclientpackage/MUSHclient/MUSHclient/worlds/plugins/text_substitution.xml

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 15 May 2016 08:22 PM (UTC)

Amended on Mon 16 May 2016 06:11 AM (UTC) by Nick Gammon

Message
The general technique for keeping colours is mentioned there:

Template:faq=23 Please read the MUSHclient FAQ - point 23.


That was for sending to another world, but you can just as easily send to the same world. However changing the text is not trivial if it spans a style run. In fact, you could almost call it undefined. Let's say we have this:


The quick brown fox
^^^ ^^^^^ ^^^^^ ^^^
red green blue  pink


And you want to have have a trigger that changes "The quick brown fox" to "The rapidly expanding universe" and keeps the colours. How does it even do that? By character position? By word count? By keeping the first colour (red in this case)?

If the word to be changed is in the same style (basically, the same colour, and same bold/underline/italic style) then you could just do a string.gsub on each style run rather than the whole line, and then re-output it as shown in the FAQ.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sun 15 May 2016 09:33 PM (UTC)

Amended on Mon 16 May 2016 06:10 AM (UTC) by Nick Gammon

Message
Here is an example, a trigger that changes "hp" to "HitPoints" in a prompt line, keeping the entire line in its original colour.


<triggers>
  <trigger
   enabled="y"
   match="&lt;*&gt;*"
   omit_from_output="y"
   send_to="14"
   sequence="100"
  >
  <send>

  for k, v in ipairs (TriggerStyleRuns) do
    text = string.gsub (v.text, "hp", "HitPoints")
    ColourTell (RGBColourToName (v.textcolour), RGBColourToName (v.backcolour), text)
  end -- for
  Note ()  -- finish line off

  </send>
  </trigger>
</triggers>


This is based on "hp" being a single colour (and thus being in one of the style runs).

Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.

- 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.


2,848 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 FutureQuest]