A simple event handler to log into a MUSH
Right - I'm aware of how that goes - and Mudlet doesn't (yet) support automatically logging into that sort of things in that way. I have a PR pending that would have solved that - but it got kicked into the long grass (around 5 years ago) and there is now a tree growing up through it..,
Instead you will either have to continue doing it manually. Or it is possible to write a script that gets run by an "event handler" that runs when the connection to the MUD/MUSH/MOO is made.
24 Replies
Open the Editor and goto the "Scripts" view by clicking on the "Scripts" button on the main toolbar:

Click on the "Add script" button:

Copy the following text into the box with the "-- add you Loa code here" placeholder:
I made an error in the above - which I have now fixed - but I used
myName
where I meant to say characterName
in all but the last image following:
Copy the text (only the letters before the
(
) after the word function
into the "Name:" box.
Normally you can call a "script" anything you like but an "event handler" is a special case as the function
in that white-ish box whose name matches the script name is the one (and there can be loads in that area) that gets called to "handle" the "event".
Now we need to tell the script which event(s) we want it to handle - and for this case it is (case-sensitive) the
sysConnectionEvent
one. So type that into the "Add User Event" box:
And press the "+" button on the right to add it in:

Can you put your "name" as "connect name password" I would imagine? (disregard how it would be visible to someone on your computer and whatnot)
Change the texts inside the
"
..."`` to the ones you want for this profile...
:neko_facepalm:
Um, well, yeah, I guess it would - although then any script using the
getCharacterName()` function could read it...
!api getCharacterNameYou may want to take a look at
getCharacterName()
. Its documentation can be found at https://wiki.mudlet.org/w/Manual:Lua_Functions#getCharacterNameThe above would leave (or use) a global
characterName
variable with the name that is enter here (unless the variable is already created elsewhere) but the function above does it's best to avoid myPassword
from being seen by anything else in the Lua subsystem by keeping it local
and nil
ling it out after use...
In use, when Mudlet connects to the Server the sysConnectionEvent
event is raised and sent to anything - like this script - is listening out for it. Then the "event" which is a collection of string arguments gets passed to the function with the same name as the script - for this one it is just the event name itself (which is ALWAYS the first "argument") - in the (
...)
for the "function" is a list of argument names to get those arguments - and in this case it is just _
which is usually used to mean "we don't care what it is as we are going to ignore it/not use it". We can do it in this case as the handler is only set up to handle one event and we already know what it is going to be ,
!eventDocumentation for Mudlet raised events can be found at https://wiki.mudlet.org/w/Manual:Event_Engine>
Sod, it, @demonnic the above link is rong - it shouldn't have that
>
on the end and I can't delete it because I don't have 2FA...
https://wiki.mudlet.org/w/Manual:Event_EngineMudlet
Manual:Event Engine
Manual on events, which events exist, how to raise events, how to handle them.
Anyhow, the function is called and it then sends out the text assembled from the fixed strings joined together (by the
..
operator) with the variables using the send(...)
function - the second argument (the false
) stops it being echoed on the screen...
!api sendYou may want to take a look at
send()
. Its documentation can be found at https://wiki.mudlet.org/w/Manual:Lua_Functions#sendok, one sec
Once you have this script setup as you want it you can hit the "Save script" button and it'll be ready for the next time you connect to the Server...
!event
Documentation for Mudlet raised events can be found at https://wiki.mudlet.org/w/Manual:Event_Engine >
Mudlet
Manual:Event Engine
Manual on events, which events exist, how to raise events, how to handle them.
hmmm
trying to avoid it embedding the block
I'll futz with it a little later
Oh, 💩 , I made a typo - I used
myName
instead of characterName
which won't work. It should look like this: