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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Exactly how bad is it to call Simulate instead of ColourNote anyway?

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Exactly how bad is it to call Simulate instead of ColourNote anyway?
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by FenceWalker   USA  (8 posts)  [Biography] bio
Date Mon 09 May 2011 05:01 AM (UTC)  quote  ]

Amended on Mon 09 May 2011 05:02 AM (UTC) by FenceWalker

Message
Fiendish said:

Then I think about what the zMUD documentation says about the #substitute command. It says that "Substituted strings are not processed by further triggers".


The documentation for CMUD says the same thing about #sub. However if you were to make a trigger in either CMUD or ZMUD (not sure about the free version I tested in 7.21), that took a string and substituted it with something else. Then made another trigger to fire on the substituted string, you'll see that the documentation for #sub is incorrect. Triggers WILL fire on #sub'ed lines.

Just wanted to correct that small bit of misleading information that is getting quoted from outdated help files.
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Sat 07 May 2011 06:28 PM (UTC)  quote  ]
Message
Well, you could describe it that way. I think of it more as a normal string including style information. You need the whole string in one place to be able to do replacements properly, and I just kind of ignore the 'text' field in each style.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Sat 07 May 2011 05:22 PM (UTC)  quote  ]
Message
Twisol said:

I was going to finish my stylestring implementation before...

So stylestring is just an object that also contains the non-styled string representation of a style run?

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Thu 05 May 2011 04:33 AM (UTC)  quote  ]
Message
Quote:

match="^.*$"


Yeah, exactly like that. :)

- Nick Gammon

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

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Thu 05 May 2011 04:22 AM (UTC)  quote  ]
Message
Nick Gammon said:
Now one thing that springs to mind is making a generic trigger (ie. it matches "*").

Then you feed that trigger into your own matching system that might change A to B, and then C to D and so on.

In other words, what I just implemented. ;)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Thu 05 May 2011 04:14 AM (UTC)  quote  ]
Message
Fiendish said:

... one of the first things they ask is "How do I do #sub in MUSHclient?"


Well that is like the people that ask where is Lua's switch statement.

If I may suggest, doing a #sub isn't all that critical. I mean, when you are fighting mobs you don't think "oh I wish I could do a #sub"!

What you *might* think is "I want better stats" or "have I seen this mob before?" or "is that one of my friends?".

So I suggest the emphasis should be pulled back from "how can we #sub?" to "how can we solve the underlying problem?".

Now one thing that springs to mind is making a generic trigger (ie. it matches "*").

Then you feed that trigger into your own matching system that might change A to B, and then C to D and so on.

- Nick Gammon

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

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Wed 04 May 2011 06:51 PM (UTC)  quote  ]

Amended on Wed 04 May 2011 06:52 PM (UTC) by Twisol

Message
Not built-in, and not the way you wanted to do it, no. There's still the virtualized trigger I suggested before; in fact I wrote and tested it already last night. I was going to finish my stylestring implementation before posting it, but why not:
stylestring = {}

function stylestring.new(str, styles)
  return setmetatable({
    str = str,
    styles = styles,
  }, {
    __index = stylestring,
  })
end

function stylestring.tell(self)
  local str, styles = self.str, self.styles
  local left = 1
  for _,t in pairs(styles) do
    local fg = RGBColourToName(t.textcolour)
    local bg = RGBColourToName(t.backcolour)
    ColourTell(fg, bg, str:sub(left, left + t.length - 1))
    left = left + t.length
  end
end
function stylestring.note(self)
  self:tell()
  AnsiNote() -- not sure if Note() preserves the current color, but I know this does
end

function stylestring.replace(self, match, replace)
  -- TODO: Stretch/shrink styles as needed.
  -- Until then, this is a glorified gsub.
  local str = self.str
  local match_len = match:len()
  
  local left = 1
  local mid = str:find(match)
  while mid do
    if left then
      str = str:sub(left, mid-1) .. replace .. str:sub(mid + match_len)
      left = mid + match_len
    end
    mid = str:find(match, left)
  end
  
  self.str = str
  return self
end

local subs = {}
function add_sub(match, replace)
  table.insert(subs, {
    match = match,
    replace = replace,
  });
end

function do_sub(str)
  for _,t in ipairs(subs) do
    str = str:replace(t.match, t.replace)
  end
  return str
end

function get_subs()
  return subs
end


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   keep_evaluating="y"
   match="^.*$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>local str = stylestring.new("%0", TriggerStyleRuns)
do_sub(str):note()</send>
  </trigger>
</triggers>


<aliases>
  <alias
   match="^\s*#sub\s*{((?:[^}]|\})+)}\s*{((?:[^}]|\})+)}\s*$"
   enabled="y"
   omit_from_log="y"
   regexp="y"
   send_to="12"
   omit_from_output="y"
   ignore_case="y"
   sequence="100"
  >
  <send>add_sub(("%1"):gsub("\\}", "}"), ("%2"):gsub("\\}", "}"))</send>
  </alias>
</aliases>

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Wed 04 May 2011 06:46 PM (UTC)  quote  ]

Amended on Wed 04 May 2011 06:48 PM (UTC) by Fiendish

Message
So this all seems very unfortunate for me. I'm reading that it means I can't do what I want to do here.

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 04 May 2011 10:29 AM (UTC)  quote  ]

Amended on Wed 04 May 2011 10:30 AM (UTC) by Nick Gammon

Message
Twisol said:

When I talked about a Simulate()d line being displayed out of order, I meant that it's very likely that one chunk of data will contain multiple lines.


I agree with Twisol here.

As a thought experiment, imagine that each character from the MUD arrives separately, possibly separated by minutes of delay. Now in practice it isn't that bad, but when you propose design changes, make sure they are compatible with that model.

- Nick Gammon

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

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Wed 04 May 2011 09:27 AM (UTC)  quote  ]
Message
Fiendish said:

So hold on...Back to what you said earlier:

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

So I've been playing around, and I've gone and replaced the series of ColourTell/ColourNote calls with

Simulate(stylesToANSI(styles))

where stylesToANSI does what its name implies. And it appears to be working great for me. Everything is in the right place, and I'm not splitting lines down the middle. Granted I have a fast connection and a fast computer. Are you saying that this will work differently for other people on the same MUD, or is it server dependent, or what? I'm not at all familiar with the packet level of MUD transmission.


Nick will be able to confirm or deny the inner workings of Simulate, but I'll explain the whole packet transmission thing.

You probably know that MUDs communicate using the Telnet protocol. Hower, Telnet sits on top of TCP, which is a "reliable, stream-based protocol". Stream-based means that you as a user do not deal with packets, you deal with a stream of data. Data you pass to a TCP socket is buffered up, and some/all of that data is sent as a packet. On the other end, incoming packets are buffered up, and you request chunks of data in whatever size you want. This means that if the server sends "Take me to your leader", a variety of things can cause the client to process "Take me to" and " your leader" in separate passes.

Compare this to UDP, which is an unreliable datagram protocol. It doesn't guarantee that data will be received in order, or even at all, and you deal directly with discrete packets of data. However, a datagram is never split up.

When I mentioned bisecting a line, I was talking about part of a line getting processed separately from the rest. If Simulate() appends data to the buffer of data currently being processed, it effectively wedges inbetween two chunks of incoming data. This kills kittens.

When I talked about a Simulate()d line being displayed out of order, I meant that it's very likely that one chunk of data will contain multiple lines. By appending the Simulate()d data to the end of the chunk, you're moving that line past the others.


It's possible that Simulate() has its own, separate buffer that's only processed when there's no more data available, but the vagaries of the 'net makes that an unreliable technique. (Better than the alternative, though - at least it works most of the time.)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Wed 04 May 2011 09:12 AM (UTC)  quote  ]

Amended on Wed 04 May 2011 09:13 AM (UTC) by Fiendish

Message
So hold on...Back to what you said earlier:

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

So I've been playing around, and I've gone and replaced the series of ColourTell/ColourNote calls with

Simulate(stylesToANSI(styles))

where stylesToANSI does what its name implies. And it appears to be working great for me. Everything is in the right place, and I'm not splitting lines down the middle. Granted I have a fast connection and a fast computer. Are you saying that this will work differently for other people on the same MUD, or is it server dependent, or what? I'm not at all familiar with the packet level of MUD transmission.

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Wed 04 May 2011 08:53 AM (UTC)  quote  ]
Message
Twisol said:

Fiendish said:
Wait, do we get to pick how it should work?

I do, I'm writing a client. ~_^
Will it be compatible with MUSHclient scripts? :P
I kid, Nick! I kid!

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Wed 04 May 2011 08:52 AM (UTC)  quote  ]
Message
Fiendish said:
Wait, do we get to pick how it should work?

I do, I'm writing a client. ~_^

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Wed 04 May 2011 08:48 AM (UTC)  quote  ]

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.

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 04 May 2011 08:48 AM (UTC)  quote  ]
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
[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.


4,258 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]