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
SlySven ☕
SlySven ☕OP4w ago
Open the Editor and goto the "Scripts" view by clicking on the "Scripts" button on the main toolbar:
SlySven ☕
SlySven ☕OP4w ago
No description
SlySven ☕
SlySven ☕OP4w ago
Click on the "Add script" button:
SlySven ☕
SlySven ☕OP4w ago
No description
SlySven ☕
SlySven ☕OP4w ago
Copy the following text into the box with the "-- add you Loa code here" placeholder:
function onConnectionFunction(_)
characterName = characterName or "Slysven"
local myPassword = "password"

send("connect " .. characterName .. " " .. myPassword, false)

myPassword = nil
end
function onConnectionFunction(_)
characterName = characterName or "Slysven"
local myPassword = "password"

send("connect " .. characterName .. " " .. myPassword, false)

myPassword = nil
end
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:
SlySven ☕
SlySven ☕OP4w ago
No description
SlySven ☕
SlySven ☕OP4w ago
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".
SlySven ☕
SlySven ☕OP4w ago
No description
SlySven ☕
SlySven ☕OP4w ago
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:
No description
SlySven ☕
SlySven ☕OP4w ago
And press the "+" button on the right to add it in:
No description
atari2600tim
atari2600tim4w ago
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)
SlySven ☕
SlySven ☕OP4w ago
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 getCharacterName
Carl-bot
Carl-bot4w ago
You may want to take a look at getCharacterName(). Its documentation can be found at https://wiki.mudlet.org/w/Manual:Lua_Functions#getCharacterName
SlySven ☕
SlySven ☕OP4w ago
The 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 nilling 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 , !event
Carl-bot
Carl-bot4w ago
Documentation for Mudlet raised events can be found at https://wiki.mudlet.org/w/Manual:Event_Engine>
SlySven ☕
SlySven ☕OP4w ago
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_Engine
Mudlet
Manual:Event Engine
Manual on events, which events exist, how to raise events, how to handle them.
SlySven ☕
SlySven ☕OP4w ago
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 send
Carl-bot
Carl-bot4w ago
You may want to take a look at send(). Its documentation can be found at https://wiki.mudlet.org/w/Manual:Lua_Functions#send
demonnic
demonnic4w ago
ok, one sec
SlySven ☕
SlySven ☕OP4w ago
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...
demonnic
demonnic4w ago
!event
Carl-bot
Carl-bot4w ago
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.
demonnic
demonnic4w ago
hmmm trying to avoid it embedding the block I'll futz with it a little later
SlySven ☕
SlySven ☕OP4w ago
Oh, 💩 , I made a typo - I used myName instead of characterName which won't work. It should look like this:
No description

Did you find this page helpful?