Mudlet 4.11 highlights

Meatspace asserts itself always, but sometimes more than others. I’d meant to get this post out over the weekend but that didn’t work out for various reasons. Regardless, one of the things I’d like to do with this blog is highlight various features of the client which I think are either under-utilized or are new in an effort to get the word out. A lot of this is touched on in the release post as well but bears repeating or a bit more of a dive, and some of it didn’t make it to the highlights reel for that post but are worth a mention in my opinion.

So with that being said, here are some of the more exciting bits out of the Mudlet 4.11 release.

Italics/Bold/Underline in c/d/hecho

An oft-requested feature, finally these formatting options are parsed in cecho, decho, and hecho. I use the backtick (`) as my lua alias since I use it so often.

getWindowWrap(windowName)

Another small one, but when formatting text it can be super helpful to get the wrap width of a console.

Drag and drop URL installs

You have been able to drag and drop Mudlet packages onto the Mudlet window to install them for a few versions, but now you can drag and drop a url from your web browser onto Mudlet and it will download and install the package for you.

Named captures in perl regex triggers

Another one that’s been requested a few times finally makes its way into Mudlet thanks to the efforts of Mudlet’s newest member of the core dev team, Delwing. The release post includes some pictures, but briefly:

-- old way
-- regex pattern: ^The mystical magical aura around (\w+) turns a deep vermillion and you feel your blood boil, doing (\d+) damage$

-- code
cecho("Blood boiled by " .. matches[2] .. ":<red> " .. matches[3] .. "\n")
-- new option
-- regex pattern: ^The mystical magical aura around (?<attacker>\w+) turns a deep vermillion and you feel your blood boil, doing (?<dmg>\d+) damage$

-- code
cecho("Blood boiled by " .. matches.attacker .. ":<red> " .. matches.dmg .. "\n")

-- above code would also work with the following pattern, making it easier to combine patterns where the captures come in different order
-- regex pattern: ^You take (?<dmg>\d+) damage as your blood boils, a faint red mist rising from your skin and flowing towards (?<attacker>\w+)\.$

String interpolation (formatting)

One piece of syntactic sugar whose lack is often bemoaned is string interpolation. “What is string interpolation?” I hear some of you thinking. It’s a fancy way developers describe replacing things inside strings with their value. The version Mudlet uses is modified from the f-strings luarock, which is primarily aimed at Lua 5.2+ and had to be slightly modified to work in Mudlet. It replaces anything inside { } with the outcome of the expression. It may be easiest to show with a few quick examples.

-- You could rewrite the code for the triggers above like this
cecho(f("Blood boiled by {matches.attacker}:<red> {matches.dmg}\n"))

-- Lua allows you to call functions with a single string or table argument without the parentheses. This is usually considered bad practice, but this is one place I will often make an exception
cecho(f"Blood boiled by {matches.attacker}:<red> {matches.dmg}\n")

-- You can run functions as part of the string. Assuming you have written a function getDamageColor which returns different colors based on how much damage you took, you could run the echo as follows:
cecho(f"Blood boiled by {matches.attacker}:{getDamageColor(matches.dmg)} {matches.dmg}\n")

Save/load Mudlet map to/from JSON

Right now, the Mudlet map saves as a binary file, the actual map item in the code being serialized to disk. With the 4.11 update it can now save and load in the JSON format. This has several benefits, among them that it is human readable. This makes it much easier to manage inside Git for people who maintain crowd maps, providing manageable diffs and much smaller repositories due to the way git handles binary vs ascii files. Also provides an official JSON format to code against for things like the web viewer for Mudlet maps, or perhaps a future program which allows you to add/remove rooms from the json file without being inside Mudlet itself. We’ll see what people come up with =)

Conclusion

Mudlet 4.11 took a while longer than was hoped due to Travis CI essentially turning its back on FOSS with its new pricing model, but should hopefully get back to regular releases soon. The combination of string interpolation, named captures in regex triggers, and the addition of formatting codes for bold, underline, and italics to the c/d/hecho functions in particular will allow for much easier to read code when doing complicated string formatting and combining multiple patterns which do the same thing in your trigger editor.