The wiki tells us here that it's a good idea to namespace our functions. This process baffled me for the longest time. If you're in the same boat, here's a template and some instructions to make it easy to convert your own scripts to a nameSpace version. Credits: this is adapted from The Aaron's many scripts that use the technique. If I've missed any pitfalls, I'm sure more experienced scripters can offer advice. But this process has worked flawlessly for me quite a few times now. Step 1: create a new script, and paste this into it: var myNameSpace = myNameSpace || (function() {
'use strict';
var version = '1.0',
handleInput = function(msg) {
// copy the body of your on(chat:message) event to this function
},
myFunctionName = function(args){
// for each function, copy this function and swap myFunctionName for function name, and put any arguments in args.
// then paste the body of your function into the body of this one.
},
registerEventHandlers = function() {
on('chat:message', handleInput);
// if you have any other on events, you can enter that here and create a function above, like handleInput, to intercept it.
};
return {
RegisterEventHandlers: registerEventHandlers
};
}());
on("ready",function(){
'use strict';
myNameSpace.RegisterEventHandlers();
});
2) pick a namespace for your function, and do a global replace, swapping "myNameSpace" for your chosen namespace.
3) create any event handlers you need under the registerEventHandlers function.
If your script responds to chat, you can skip this step, it's already set up.
4) copy the body of the on(chat:message) event into the handleInput function. Repeat for any other other events
5) if you have any functions, make a copy of myFunctionName for each swap "myFunctionName" for the name of your function,
copy the body of old your function to the body if this new function.
if needed, add any args in the title line of the function.
That should be it. Test and and see what happens