The reason why you got that error is because you try to use a child function of an undefined variable "ChatWnd". A fix would be to send the ChatWnd object as a parameter to your foo function, like so:
code:
var test1 = 'Hello World!';
function OnGetScriptCommands()
{
var ScriptCommands = "<ScriptCommands>";
ScriptCommands += "<Command>";
ScriptCommands += "<Name>test</Name>";
ScriptCommands += "<Description>testing</Description>";
ScriptCommands += "</Command>";
ScriptCommands += "</ScriptCommands>";
return ScriptCommands;
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
switch (Message) {
case "/test":
foo(ChatWnd);
break;
}
}
function foo(ChatWnd) {
ChatWnd.SendMessage(test1);
}
Or, you could use a return to replace the sent message:
code:
...
switch (Message) {
case "/test":
return foo(ChatWnd);
break; //not really necessary, it simply makes it look more common.
}
...
function foo(ChatWnd) {
return test1;
}