Without a delay of some sort you can wind up with line breaks in unanticipated places and triggers which won’t fire consistently, and that’s no good either. This is because by default there is a 300ms wait to make sure the game has sent everything it needs to send and there aren’t more packets waiting to come in which may contain part of the line. One common complaint with Mudlet on games which cannot be configured to send the telnet GA (Go Ahead) or EOR (End of Record) signals with their prompt is that it can feel a bit sluggish. PrintError("This is an error and shows up anywhere using error() would", true, true) show new printDebug and printError function outputs Adjustable wait time for non-GA/EOR games prints big red error, including stack trace, and halts execution PrintError("This is an error and shows up anywhere using error() would", true) prints big red error, including stack trace. PrintError("This is an error and shows up anywhere using error() would") PrintDebug("This is a debug message, will only show in the error console in the script editor", true) prints calm green debug message, with stacktrace PrintDebug("This is a debug message, will only show in the error console in the script editor") I aim to replace all of these with printError and printDebug. Mudlet added debugc which allows for non-error messages to be printed to the error console, but it was not much different than a normal echo to a hidden miniconsole for debugging, and in my experience goes largely unused by most. Its error and assert functions do not print nearly enough stack trace information, and options for printing error messages without halting execution were nonexistent. One of the things which Lua is not so great at in my opinion is error handling. These two functions on their own would cut way down on my own boiler plate code, but there are also stopNamed*, resumeNamed*, deleteNamed*, and getAllNamed* functions which should make working with tempTimers and named event handlers even easier and more convenient. No matter how many times you call registerNamedTimer or registerNamedEventHandler with the same names it will replace and restart them rather than allowing them to stack. This is similar to the API for managing GMCP modules. In the latter case this helps to keep all of a particular package’s events and timer’s logically bundled together in the same manager. These are both picked by you, and I would recommend using your own handle or character name for the first one if it’s just scripts you’re writing for yourself, or your package name for scripts you’re writing to give to others. The second parameter is the name of the timer or event itself. The first parameter identifies what ‘name’ to file the handlers under, so that you can keep the timer/handler names themselves simpler without colliding with the names used by others. MyTable.idmgr:registerEvent("vitals", "", "myTable.handleVitals") MyTable.idmgr:registerTimer("super cool thing", 4, function() doSuperCoolThingInFourSeconds() end) MyTable.idmgr = myTable.idmgr or getNewIDManager() for those who prefer to work with Lua 'objects' RegisterNamedEventHandler("Demonnic", "vitals", "", "myTable.handleVitals") RegisterNamedTimer("Demonnic", "super cool thing", 4, function() doSuperCoolThingInFourSeconds() end) MyTable.vitalsID = registerAnonymousEventHandler("", "myTable.handleVitals") KillAnonymousEventHandler(myTable.vitalsID) MyTable.timerID = tempTimer(4, function() doSuperCoolThingInFourSeconds() end) One of the more frequent issues I hear from people while sitting in the help channel is that they’ve got multiple tempTimers stacking up for the same thing, or their old anonymous event handlers aren’t cleaned up and fires four times for each raiseEvent call. Mudlet 4.14 will ship with a new internal IDManager which will manage the work of killing and recreating temp timers and event handlers for you, rather than forcing you to capture return IDs and handle it yourself. Named tempTimers and not-so-anonymous event handlers The editor theme in the left picture is the default ‘Mudlet’ theme, on the right is ‘Monokai Midnight’ which is the one I usually use. On the left above is the ‘light’ mode most Mudlet users are presented upon first install, followed by a picture highlighting where the option is in the preferences dialog, and finally a picture which shows a similar picture to the first, but in dark mode.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |