OnConnect

Posted by Katie Love on Fri 16 Jan 2009 08:01 PM — 11 posts, 37,788 views.

#0
I have a bunch of variables I would like reset on connect. Is there a way I can trigger an alias or script when I connect to a mud? It seems like something easy that should be documented but I've been trying and I can't seem to find the information.

Thanks!!!
USA #1
Go to the Scripting... Preferences (CTRL+SHIFT+6)

And fill in the names of Script functions into any World Events that you want. :)
Amended on Fri 16 Jan 2009 08:21 PM by WillFa
#2
Thanks!

It's working now -- but...

Every time I seem to make a change to my aliases/triggers/etc it is dropping the script file and I'm having to reload it. It must be a setting somewhere. It's really annoying to have to reload it all the time.

Anyone experience this?
Australia Forum Administrator #3
What do you mean by "dropping the script file"?

Normally simply changing an alias should not affect the current script file.
#4
Since it looks like I have to move at least one alias into a script, I figured I should resurrect this thread.

The error message I get can be found here: http://imagebin.ca/view/szC-x6ml.html

The error message appears everytime I hit "ok" or "cancel" on the Configuration window (the window where I can add aliases, macros, scripts, varaible, etc)

My Achaea.lua file contains the following:
function OnConnect (name, line, wildcards)
SetVariable("Connecting", "1")
end -- function

The only other relevant piece I can thing of is in the configuration window, under World Events. A screenshot of that is here: http://imagebin.ca/view/SMGGew.html

Thanks!!!
Australia Forum Administrator #5
Can you show the whole scripting configuration window, not just the bottom bit?

Anyway, the OnConnect function does not take arguments (name, line, wildcards: only apply to aliases and triggers). However that won't matter under Lua.


#6
The entire window is here: http://imagebin.ca/view/VeNPn5LK.html

I've tried multiple combinations of things. Rather frustrated right now :-(...
Australia Forum Administrator #7
I can't really explain it. I tried myself and the OnConnect worked fine.

The only things I can think of are:

  • Some subtle spelling problem, where an "oh" is a zero somewhere. Try copying and pasting the OnConnect word from the script configuration to the script file to make sure.
  • The script file you pasted is not in fact the one referenced in the script configuration (that is, you have two Achaea.lua files). Try hitting the Edit button in the script configuration to confirm that the correct file actually opens.


BTW - what version of MUSHclient are you using?
Amended on Fri 20 Feb 2009 04:18 AM by Nick Gammon
#8
I'm running MUSHclient 4.37.

Sadly, I have thought of both of those things and tried them. They didn't work. I actually just tried them again for giggles and it still didn't work.

I would love to move some things into the script file -- in fact i'm about to create a recursive funciton, which would need the script file. I've tried reinstalling as well.

I can't shake the feeling it's some small thing, but I can't figure out what.
#9
** Update **

I changed the function name from OnConnect to Foo and it *appears* to be working. I've been trying to get the error to pop up again with no success.

Of course, I'll want to do some scripting for a bit before i'm 100% sure this worked. Is it possible OnConnect is some sort of reserved word?
Australia Forum Administrator #10
No it isn't.

My only explanation now is that your script file is perhaps larger than the 3 lines you posted, and that somehow you change the OnConnect variable to something else. For example:


function OnConnect ()
print "connected"
end -- OnConnect

--- 500 lines of code here ...

OnConnect = {}


Now that code gives the error message "The world connect subroutine named "OnConnect" could not be found." - this is because OnConnect is now a table and not a function.

One thing you could try is, after processing the script file, and seeing the error message, go into the immediate window and type:


print (type (OnConnect))


After mucking up the script file (as above) it printed "table".

It should be "function". Or maybe it would print "nil".