Reconnecting and Event Handlers

Post Reply
Nethran
Posts: 2
Joined: Mon Sep 18, 2017 7:15 pm

Reconnecting and Event Handlers

Post by Nethran »

All right, so, I'm pretty sure I have no idea what I'm doing.

I started using Mudlet about 3 days ago, and I've gotten to play with it about 3 hours each day, moving scripts from cMUD to it, and while that's all going well, I just can't figure out how to keep my character connected to the MUD. My lappy's network adapter is a piece of crap and it randomly disconnects/reconnects since I upgraded to Windows 10. That's not the issue, though.

How do I properly implement usage of the sysDisconnectionEvent event? Right now, I have it registered to a function that reads:

Code: Select all

function autoconnect(event)
echo("Disconnected!")
expandAlias("try_connect")
end -- autoconnect

registerAnonymousEventHandler("sysDisConnectionEvent", "autoconnect")
I'm not sure the "(event)" is needed in the function definition, but I tried it without and that doesn't work either. :(

The alias just tries to reconnect, then again every 10 seconds using reconnect() until a trigger sets "connected" to true. But that's largely immaterial.

Debug doesn't seem to show any lines that would indicate it's noticed that I've lost connection, so, with my current knowledge, I'm pretty stuck.

User avatar
keneanung
Site Admin
Posts: 94
Joined: Mon Mar 21, 2011 9:36 am
Discord: keneanung#2803

Re: Reconnecting and Event Handlers

Post by keneanung »

It doesn't work because the event is called "sysDisconnectionEvent". The upper/lower casing is important here. If you change the first argument of the last line, it should work.

Nethran
Posts: 2
Joined: Mon Sep 18, 2017 7:15 pm

Re: Reconnecting and Event Handlers

Post by Nethran »

And so it does. Typos will be the death of me. Thank you.

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Reconnecting and Event Handlers

Post by SlySven »

Yeah, I've made the odd smelling mistake myself... :rofl:

Technically your function will receive one argument if it is set up as an event handler {the name of the script has to match that function if that is to be so, so it too must be named "autoconnect"} that being the name of the event concerned sysDisconnectionEvent in this case {which is needed if you have a common event handler for several events} :ugeek:

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Reconnecting and Event Handlers

Post by Jor'Mox »

SlySven wrote:
Thu Sep 21, 2017 12:53 am
Technically your function will receive one argument if it is set up as an event handler {the name of the script has to match that function if that is to be so, so it too must be named "autoconnect"} that being the name of the event concerned sysDisconnectionEvent in this case {which is needed if you have a common event handler for several events}
The script name can be anything he wants, since he is using the registerAnonymousEventHandler function, rather than the GUI system that has the requirement you speak of. And in this case, he can certainly leave the "event" argument out of the function, but given how he wrote it, it may not be clear that he still needs the empty parentheses even if his function doesn't take any arguments. Of course, I always have not only the event argument, but also something to take variable numbers of arguments in all of my event handler functions, since many events include arguments, which I often want to work with. That seems likely a bit beyond what he is going to be needing at this point though.

Post Reply