ID:724170
 
This is a little snippet that I intend to use for my MUD projects. In my original projects I would queue any messages sent in the same tick, send them at the same time, and then add a linebreak. I find this to be a big antiquated though.

Instead, let's go with something that'll separate messages that need to be separated in a given period of time and skip all this unnecessary background processing.

To do this, we'll make a message mode system that groups messages of the same category and separates ones of different category. Basically, if the previous message is the same type of message as the one being sent, do not separate it. If it's not though, add a little linebreak to separate it.

client
var
currentMessageMode = null

proc
// this is essentially for when we're gonna print a message, and we don't want
// it separated from the next message, no matter what.
clearMessageMode()
currentMessageMode = null

// send a message with a particular "mode" or "category".
// if the previous message sent does not match this message's mode, send a
// linebreak to separate this one from the previous, since they aren't related.
sendMessage(message, mode)
if(currentMessageMode != mode && currentMessageMode != null)
src << ""

src << message
currentMessageMode = mode


This can be used in games where you use the same output for everything; in my case, MUDs certainly do this, in general. With a lot of text coming at you all the time, it's good to visually see when messages are related or not. And the existence of a separating line will point that out pretty well.

My personal usage will look something like this. If a user is set to echo, clear the message mode so that the next message sent after the echo isn't separated from it. This'll make it so if the user's CLIENT echoes, we don't end up with a stupid linebreak after their echo, since that's handled locally for them. We don't decide when their client does that.
Interesting idea