Shoutbox

Script Command - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Script Command (/showthread.php?tid=72563)

Script Command by Bewwen on 03-11-2007 at 08:35 PM

Hello..

I tried to make my own command. Like this: /test
It doesnīt matter how I try.. I canīt get this to work..


-------------------------------------------------------------------------

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)
{

        <<Some kind of switch>>   (donīt know how)

    switch ("some thing") {
        case "/test": return function();
    }
}

function() {
    ChatWnd.SendMessage(test1);
}


-------------------------------------------------------------------------

can someone explane the switch and how to use it..
and the return when you have typed the "/test".. I am not sure if thatīs correkt either :D


//Bewwen


RE: Script Command by effection on 03-11-2007 at 08:41 PM

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":
                        function foo();
                break;
        }
}
function foo() {
ChatWnd.SendMessage(test1);
}


RE: Script Command by NanaFreak on 03-11-2007 at 08:45 PM

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();
break;
}
}
function foo() {
ChatWnd.SendMessage(test1);
}

that should do it ;)
RE: Script Command by Bewwen on 03-11-2007 at 09:07 PM

nope.. same error as before..

It just says that "test" is an unknowned command and that I should use 2 / instead :(

whatīs wrong then?


RE: Script Command by effection on 03-11-2007 at 09:12 PM

yes i am getting that error with my new script i have created :( it happens even if i place the commands inside the ScriptInfo.xml file... is it a bug?


RE: Script Command by Bewwen on 03-11-2007 at 09:14 PM

I have no idea.. but it is not very funny :D


RE: Script Command by NanaFreak on 03-11-2007 at 09:14 PM

quote:
Originally posted by effection
yes i am getting that error with my new script i have created :( it happens even if i place the commands inside the ScriptInfo.xml file... is it a bug?
no its not a bug....

also you might want to look here: http://mpwiki.net/Script_Commands
RE: Script Command by markee on 03-11-2007 at 10:06 PM

You have to return an empty string with commands, so it will be...
var test1 = 'Hello World!';

code:
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();
return "";
break;
}
}
function foo() {
ChatWnd.SendMessage(test1);
}

RE: Script Command by effection on 03-11-2007 at 10:24 PM

plus has a wiki? haha ooh well i forgot about returning an null sting thanks


RE: Script Command by Felu on 03-12-2007 at 08:42 AM

quote:
Originally posted by effection
plus has a wiki?
Yes its PlusScriptWiki. Its unofficial and doesn't have much on it. I'd say reffering to the Official Scripting Documentation is better. Read the Windows Script 5.6 Documentation(it contains JScript) for any help with learning/understanding JScript :).
RE: Script Command by Spunky on 03-12-2007 at 03:44 PM

quote:
Originally posted by markee
You have to return an empty string with commands, so it will be...
var test1 = 'Hello World!';

code:
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();
return "";
break;
}
}
function foo() {
ChatWnd.SendMessage(test1);
}


Code after a return doesn't execute does it? That means that the break is not needed :p
RE: Script Command by markee on 03-12-2007 at 03:58 PM

No but I was lazy and just added the line in.  Realistically I could have at least made Message = "" in the case and return Message at the end or I could have used the likes of Cookie's RegExp for commands or something to make it better, but I thought I would just add to the code to minimise confusion (and it doesn't matter anyway).  If you really want to clean the code up then go ahead but I cba and you'll probably only confuse the new scripter (I do not mean to patronise in any way, I'm sorry if I come across as if I do).


RE: Script Command by Spunky on 03-12-2007 at 04:09 PM

I only mentioned it because they might then think that the break is still nessacerry.


RE: RE: Script Command by Matti on 03-12-2007 at 05:18 PM

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;
}