Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Exactly how bad is it to call Simulate instead of ColourNote anyway?
Exactly how bad is it to call Simulate instead of ColourNote anyway?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
Posted by
| Fiendish
USA (2,534 posts) Bio
Global Moderator |
Date
| Tue 03 May 2011 07:20 PM (UTC) Amended on Tue 03 May 2011 08:55 PM (UTC) by Fiendish
|
Message
| I find myself in a situation where I need to be able to modify parts of the same colorized output line in several different triggers (zMUD converts really do care about #sub functionality). It seems like the only sane way to do that is by using Simulate to display a colored string instead of a series of ColourTells that fake the colorized output after omitting the original line, because notes and tells aren't processed by triggers. And yet every time someone has suggested using Simulate or asked about using Simulate instead of Note/ColourNote/ColourTell, Nick says "Simulate kills kittens!"
So how bad is it anyway? Has anyone had world-collapsing experiences with it? I think it's the only reasonable option here. |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Wed 04 May 2011 12:08 AM (UTC) |
Message
| Well, do you like kittens or not? Besides, I never said that. ;)
My problem with Simulate is, apart from the fact that it wasn't designed for that, is that it will probably not work reliably.
Effectively it is injecting the simulated text into the input stream being considered by the input-handling state machine.
Now state machines are not things I like to muck around with.
Consider this sort of scenario ...
We have an MXP tag, eg. <room> so we now have a start tag but not yet the stop tag (</room>). The function OnPluginMXPopenTag is called, which calls Simulate to inject new text into the input stream. Text which might close the tag, or do something to the MXP state. After that we keep processing the original line. Now everything is out of sync.
And it might not happen every time. If the thing triggering the Simulate call happens to be at the end of a packet, then the Simulated data might just neatly appear as if it was the next thing from the MUD. But in the middle of a packet, it might not.
What are you trying to do exactly? Even if you omit a line from output, it is still processed for triggers. Do you want to change (say) X to Y and then trigger on Y? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #2 on Wed 04 May 2011 12:27 AM (UTC) |
Message
| It sounds like he has a line that multiple triggers want to modify. If two triggers re-echo the line though, you have two new lines instead of the original. It sounds like he's trying to get around that by Simulate()ing the modified line and hoping the other triggers match it too.
If this is about color instead of replacement text, however, you -can- stack color changes. You need to have one trigger that matches the line and enables a trigger group, then each of the triggers in that group can match a specific piece of that line and change its color. Then you need a trigger at the end to disable the trigger group again. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Fiendish
USA (2,534 posts) Bio
Global Moderator |
Date
| Reply #3 on Wed 04 May 2011 03:13 AM (UTC) Amended on Wed 04 May 2011 03:33 AM (UTC) by Fiendish
|
Message
| Hmm...
Aardwolf doesn't use MXP. Would that make some of these concerns go away?
So here's the much longer version of my question...
I have a plugin that reads text from the mud in the form of
Quote:
{chan ch=gtell}(Group) Ol' Dirty Fiendish: 'hmm pizza'
It does omit-from-output, then uses the following code to strip off the initial {...} part and then re-display the result as a series of ColourTells to simulate as if the {...} part had never been there.
-- strip out the tag
tag_length = string.find(styles[1].text,"}")
styles[1].text = string.sub(styles[1].text, tag_length+1)
styles[1].length = styles[1].length-tag_length
-- display
for _, v in ipairs (styles) do
ColourTell (RGBColourToName (v.textcolour),RGBColourToName (v.backcolour),v.text)
end -- for each style run
Note ("") -- wrap up line
The result is
Quote:
(Group) Ol' Dirty Fiendish: 'hmm pizza'
So far so good. Except now I'm trying to convert zMUD users, and one of the first things they ask is "How do I do #sub in MUSHclient?" And my response usually involves a lot of "well..." and "that's actually rather complicated". So I figured, since I'm such a smart guy, I can write a magic alias that would turn "#sub {*} {*}" into a new trigger, in a way similar to the #trigger and #alias aliases that have been discussed before on the forums*, with the proper code to actually achieve a style of inline substitution whereby all instances of %1 in the mud output are replaced with %2. And I can do it, no problem...except...
Now I'm in a situation where I need (at least) two different scripts modifying the same lines from the MUD, and I need them both to preserve color codes, and that doesn't seem possible unless I change all of that ColourTell stuff to Simulate instead.
* - (if you don't remember the relevant forum threads, see https://code.google.com/p/aardwolfclientpackage/wiki/CommandLineAliasesAndTriggers for my writeup for users on those two aliases)
When the user types
#sub {hello} {pizza}
#sub {friend} {pie}
they will get two triggers that SHOULD cause the line
Quote:
{chan ch=gtell}(Group) Ol' Dirty Fiendish: 'hello friend'
to be replaced, in concert with the plugin above, with
Quote:
(Group) Ol' Dirty Fiendish: 'pizza pie'
That seems not possible without Simulate. Issues of where to put color breaks for complicated coloring are unimportant right now.
Also, keeping these triggers out of a plugin is kind of important to me for this project, so even if there weren't another plugin involved fancy plugin-specific tricks would probably be a last resort. :\ |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #4 on Wed 04 May 2011 03:54 AM (UTC) |
Message
| I applaud your effort. :) It can be hard to untangle some parts of MUSHclient's API.
I would suggest using a single trigger that matches any given line (just ^ works fine, you can use %0 to get the whole thing), and checking all of the #subs inside it. You would need to write the checking and replacement logic yourself, but you do have access to the PCRE library from Lua (rex.*). Afterwards you can Note() the line back out. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Fiendish
USA (2,534 posts) Bio
Global Moderator |
Date
| Reply #5 on Wed 04 May 2011 04:24 AM (UTC) Amended on Wed 04 May 2011 04:26 AM (UTC) by Fiendish
|
Message
|
Twisol said:
I would suggest using a single trigger that matches any given line (just ^ works fine, you can use %0 to get the whole thing), and checking all of the #subs inside it. You would need to write the checking and replacement logic yourself, but you do have access to the PCRE library from Lua (rex.*). Afterwards you can Note() the line back out.
So any time anything ever wants to replace output it has to offload the task to some function somewhere else which keeps track of the entire list of all possible replacements that any plugin or trigger ever wants to do? And if anything ever doesn't use this mechanism I get duplicated output? That's not going to work. |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #6 on Wed 04 May 2011 06:12 AM (UTC) |
Message
|
Fiendish said: So any time anything ever wants to replace output it has to offload the task to some function somewhere else which keeps track of the entire list of all possible replacements that any plugin or trigger ever wants to do? And if anything ever doesn't use this mechanism I get duplicated output? That's not going to work.
Sorry, that's what happens when you have a singleton resource. You need a mechanism that can control access to the line and make sense of the substitutions. It's a lot better than always duplicating output.
And I think Simulate() will put the line on the very end of the input stream, so your line will actually be out of order. Quite possibly bisecting another line if not all of it made it into the current packet. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Fiendish
USA (2,534 posts) Bio
Global Moderator |
Date
| Reply #7 on Wed 04 May 2011 06:43 AM (UTC) Amended on Wed 04 May 2011 06:44 AM (UTC) by Fiendish
|
Message
|
Twisol said: And I think Simulate() will put the line on the very end of the input stream, so your line will actually be out of order. Quite possibly bisecting another line if not all of it made it into the current packet.
At first my response is that I'd much rather see Simulate act the same way that Note does. If Note after omit can get the line in the right place, why can't Simulate? Except perhaps using this would be quite dangerous since it allows for infinite reprocessing loops.
Then I think about what the zMUD documentation says about the #substitute command. It says that "Substituted strings are not processed by further triggers". Here, "substituted strings" means just the replacement portions, not the entire line. Which means that, if I extrapolate the meaning correctly, in fact zMUD is displaying the original line and then sending the original line to the triggers and overwriting the output with substitutions as the triggers process. I wonder if MUSHclient could be made to do the same. |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #8 on Wed 04 May 2011 06:48 AM (UTC) |
Message
|
Fiendish said: At first my response is that I'd much rather see Simulate act the same way that Note does, except. If Note after omit can get the line in the right place, why can't Simulate. But perhaps this can be quite dangerous.
Well, the difference between Simulate and Note is pretty big. Beyond where the data is put (Simulate -> incoming data buffer, Note -> output window lines), Simulate()d data also has ANSI, MXP, etc. parsed. AFAICT, the only thing that comes before it is decompression. Changing Simulate would also break backwards compatibility in a pretty big way. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #9 on Wed 04 May 2011 08:26 AM (UTC) |
Message
|
Fiendish said:
When the user types
#sub {hello} {pizza}
#sub {friend} {pie}
When this user types that, I am curious. Let's say that "hello" has colour codes in it. eg.
h<red>e<blue>l<green>l<white>o<pink>
What does the substitution do? Does it discard the original colours? In the case of friend/pie it must because the words are not the same length.
Fiendish said:
... and I need them both to preserve color codes, ...
That's why I am interested in your answer. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Fiendish
USA (2,534 posts) Bio
Global Moderator |
Date
| Reply #10 on Wed 04 May 2011 08:38 AM (UTC) Amended on Wed 04 May 2011 08:39 AM (UTC) by Fiendish
|
Message
|
Nick Gammon said:
When this user types that, I am curious. Let's say that "hello" has colour codes in it. eg.
h<red>e<blue>l<green>l<white>o<pink>
What does the substitution do? Does it discard the original colours? In the case of friend/pie it must because the words are not the same length.
I asked some people to test that for me before posting the original query. According to them, zMUD printed pink pizza. Clearly this is not perfect color preservation inside the replaced bits (in fact, I would have chosen red instead of pink, but that's not a big deal), but I mean it needs to preserve colors outside of the replaced bits and do at least a reasonable attempt at coloring the replaced bits. If I can get a system that allows for multiple-substitution, what happens to individual color codes within a substituted word is something I'll just make up and specify as "expected to behave strangely". |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #11 on Wed 04 May 2011 08:45 AM (UTC) |
Message
|
Twisol said:
It can be hard to untangle some parts of MUSHclient's API.
By design. Just joking. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #12 on Wed 04 May 2011 08:46 AM (UTC) |
Message
| I'm of the opinion that the final style run should be extended to fit the replacement text if it's bigger, or style runs should be discarded if the replacement text was shorter. So this:
h<red>e<blue>l<green>l<white>o<pink>
Would be this:
p<red>i<blue>z<green>z<white>a<pink>
And this:
fr<red>ie<blue>nd ni<green>ck
Would be this:
pi<red>e<blue> ni<green>ck
And this (hello -> hi):
Would be this:
Of course, if that's too funky, I'd prefer Fiendish's answer of "red". :P
Nick Gammon said:
Twisol said:
It can be hard to untangle some parts of MUSHclient's API.
By design. Just joking.
:D |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #13 on Wed 04 May 2011 08:48 AM (UTC) |
Message
|
Fiendish said:
Hmm...
Aardwolf doesn't use MXP. Would that make some of these concerns go away?
Colour codes?
Quote:
When the user types
#sub {hello} {pizza}
#sub {friend} {pie}
So you want the trigger to fire on something that it did *not* receive from the MUD? This is surely redefining what a trigger does?
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Fiendish
USA (2,534 posts) Bio
Global Moderator |
Date
| Reply #14 on Wed 04 May 2011 08:48 AM (UTC) Amended on Wed 04 May 2011 09:18 AM (UTC) by Fiendish
|
Message
|
Twisol said:
I'm of the opinion that the final style run should be extended to fit the replacement text if it's bigger, or style runs should be discarded if the replacement text was shorter.
Wait, do we get to pick how it should work? Then I agree with Twisol, the final style run should get extended if necessary, or styles should get dropped if necessary.
Quote: So you want the trigger to fire on something that it did *not* receive from the MUD? This is surely redefining what a trigger does?
Not exactly. I just want to be able to have lots of triggers that modify the same line based on what was sent by the MUD. You'll note that the documentation for #substitute specifies that the replacement bits (not from the mud) will not themselves get sent to triggers for processing. This is where Simulate() fails, unfortunately. |
https://github.com/fiendish/aardwolfclientpackage | 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.
71,211 views.
This is page 1, subject is 2 pages long: 1 2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top