Trouble with using sysConnectionEvent to create a custom login script.

Post Reply
mjevans
Posts: 4
Joined: Mon Aug 20, 2018 12:15 am

Trouble with using sysConnectionEvent to create a custom login script.

Post by mjevans »

I'm having trouble creating a custom login script.

I want a script to be run exactly exactly once per connection to a server, and ONLY on the connection to that server.

Maybe I'm using the script or GUI wrong.

Here's how to reproduce what I have so far in my test case.

1) connect to some system
2) Click the Scripts icon
3) Add Group + name it anything
4) Add this as the test code

echo "sysConnectionEvent\n"

5) Add sysConnectionEvent via the above Add User Event Handler (and click the + to do so)

Observed behavior:

Anytime the window is moused over it will echo that text...

Desired behavior:

This text should be printed exactly ONCE during the initial connection.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Trouble with using sysConnectionEvent to create a custom login script.

Post by Vadi »

You need to put your code into a function, not just into the script as-is. Check out https://wiki.mudlet.org/w/Manual:Event_ ... g_an_event for an example :)

mjevans
Posts: 4
Joined: Mon Aug 20, 2018 12:15 am

Re: Trouble with using sysConnectionEvent to create a custom login script.

Post by mjevans »

To clarify, you're saying that the entire code is evaluated / re-evaluated every time I mouse back in to the window, including re-registration via the in-script method (hopefully unique/limited to one call of the function)?

How is someone supposed to use the GUI to do that; or does it just not work?

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

Re: Trouble with using sysConnectionEvent to create a custom login script.

Post by Jor'Mox »

Yes, the entire script is evaluated every time, but "evaluating" a function simply means that the function is turned into a functioning block of code that can be used, the function itself is not actually executed. But code that isn't contained within a function is executed, which is actually important, because this is frequently used to declare important variables that are necessary for the functions to operate properly. The key is that to make an event handler, you need to make a function with a name that matches the name of your script, and then whenever the appropriate event is raised, that function will be called if you have registered it in the GUI for your script. That function will receive as a first argument the name of the event that is being raised (so that you can tell them apart if you have registered more than one event for that script), followed by whatever arguments have been passed with the event itself.

Here is an example of what you could do to get the login behavior you are looking for:
Code: [show] | [select all] lua
function myLoginScript(event,...)
    if event == "sysConnectionEvent" then
        sendAll("stuff","more stuff","blah")
    end
end

mjevans
Posts: 4
Joined: Mon Aug 20, 2018 12:15 am

Re: Trouble with using sysConnectionEvent to create a custom login script.

Post by mjevans »

I'm still having trouble, I know that this evaluates because when I add an echo outside of the function it prints....

However my event handler is never run, and it also doesn't receive any other events.
Code: [show] | [select all] lua
function connectLogin(event, ...)
  if event == "sysConnectionEvent" then
    echo("sysConnectionEvent")
    send("connect USER PASS")
    disableAlias(":")
    echo("login should be complete")
  else
    echo("connectLogin " .. event)
  end
end

registerAnonymousEventHandler("sysConnectionEvent", "connectLogin")
I also added the connectLogin as a 'user event handler' as described above.

Does the 'sysConnectionEvent' depend on what mudlet thinks a login is, rather than the LITERAL connection being made?

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Trouble with using sysConnectionEvent to create a custom login script.

Post by Vadi »

That should work just fine, I pasted it into a new script and:
[ INFO ] - Looking up the IP address of server:avalon.mud.de:23 ...
[ INFO ] - The IP address of avalon.mud.de has been found. It is: 91.215.74.15
[ INFO ] - Trying to connect to 91.215.74.15:23 ...
[ INFO ] - A connection has been established successfully.


sysConnectionEventconnect USER PASS
login should be complete


Avalon ist seit ueber 23 Jahren etabliert.
Unverschluesselte Verbindung

mjevans
Posts: 4
Joined: Mon Aug 20, 2018 12:15 am

Re: Trouble with using sysConnectionEvent to create a custom login script.

Post by mjevans »

That is extremely odd. It /wasn't/ working but actually closing and restarting Mudlet fixed it.

Thank you for the assistance.

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

Re: Trouble with using sysConnectionEvent to create a custom login script.

Post by Jor'Mox »

Interestingly enough, sometimes things happen that way. When Mudlet isn't behaving the way it should, sometimes it is because some things persist in memory but aren't visible in the code you see, but this is resolved when you restart Mudlet (or even just close and then reopen the profile).

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Trouble with using sysConnectionEvent to create a custom login script.

Post by Vadi »

Should be fixed but we'd need the steps to reproduce it

Post Reply