Shoutbox

im having troble with my script - 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: im having troble with my script (/showthread.php?tid=76581)

im having troble with my script by killa on 08-06-2007 at 05:23 PM

im makeing an update to my script and im adding a command to logme out with a command but i keep getting this error

code:
Error: Object expected (code: -2146823281)
       File: brb.js. Line: 26.
Function OnEvent_ChatWndSendMessage returned an error. Code: -2147352567
what does it mean cause im new to this
here the code

code:
function notify(msg){
    msg = MsgPlus.RemoveFormatCodes(msg);
    MsgPlus.DisplayToast("brb", msg, "");
}




function OnEvent_ChatWndSendMessage(ChatWnd,Message){

    if(Message == "brb"){

           
       
       
        notify("locking msn.");
        MsgPlus.LockMessenger('True');
        return '';
}
    if(Message == '/logout'){

           
       
       
        SendMessage('/all');
        SendMessage('/close');

        notify('login out.');
        Signout();
       


    }
}
sorry iv fixed it now i had to add chatwnd to sendmessage and messenger to signout
RE: im having troble with my script by pollolibredegrasa on 08-06-2007 at 05:53 PM

Signout(); should be Messenger.Signout();

code:
SendMessage('/all');
SendMessage('/close');
You don't actually need to do these, as the Signout() function does this automatically. However, the reason it isnt working is because SendMessage is a function of a ChatWnd, so using your code it should be ChatWnd.SendMessage('Message to send').

Also, instead of multiple if statements, use a select case. The following code seems to do what you want:

code:
function notify(msg){
    msg = MsgPlus.RemoveFormatCodes(msg);
    MsgPlus.DisplayToast('brb', msg, '');
}

function OnEvent_ChatWndSendMessage(ChatWnd,Message){
    switch (Message){
        case 'brb':
            notify('locking msn.');
            MsgPlus.LockMessenger('True');   
            return '';
        case '/logout':
            notify('login out.');
            Messenger.Signout();
    }
}


Hope this helps :)
RE: im having troble with my script by killa on 08-07-2007 at 01:40 PM

hy thanks i never knowen how to do cases thank you


RE: im having troble with my script by Volv on 08-07-2007 at 01:55 PM

quote:
SendMessage('/all');
SendMessage('/close');
And you need SendMessage('/all /close'); instead...
RE: im having troble with my script by killa on 08-08-2007 at 10:00 AM

i need some more help iv now added if some one says bye its says hurry up or get lost ill kill you whoever
jk jk
then if i say bye i say it to my self
heres the code
dont take out activate thats so my mom carnt use them

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message1, MessageKind)
{

switch(Message1)
{
case "brb":
if (activate == 1)
{
ChatWnd.SendMessage('okey dokey');
}
break
case "bye":
if (activate == 1)
{
ChatWnd.SendMessage('ok if u dont get lost soon i will kill you '+ Origin);
ChatWnd.SendMessage('jk jk');
}
break
}
}


RE: im having troble with my script by Volv on 08-08-2007 at 10:40 AM

First, it would be a lot easier to have the switch nested inside the activate check, instead of having a whole bunch of activate checks.

Secondly, as said in the Scripting Docs (here), the ChatWndReceiveMessage event is triggered whenever anything is added to the history box in a chat window which includes messages sent by yourself. As such you must compare the Origin parameter to your current nickname to check that it was not you who sent the message before making any responses.

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message1, MessageKind)
{

if (activate == 1 && Origin != Messenger.MyName) {
    switch(Message1)
    {
        case "brb":
        ChatWnd.SendMessage('okey dokey');
        break;

        case "bye":
        ChatWnd.SendMessage('ok if u dont get lost soon i will kill you '+ Origin);
        ChatWnd.SendMessage('jk jk');
        break;
    }
}

}

NOTE: A known limitation is that if a user uses the exact same nickname as yourself they will be recognised as you, and as such will not be responded to by the script.
RE: im having troble with my script by LifelesS on 08-08-2007 at 10:51 AM

You could have it done with 2 arrays, like:

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    var receive = new Array("brb", "bye");                                                //on this array you store the arriving messages
    var send = new Array("okey dokey", "ok if u dont get lost soon i will kill you\njk jk");    //on this array you store the sending messages
    //note that they have to match in the array order

    if(Origin != Messenger.MyName && activate == 1)            //very important, or you would asnwer yourself if you typed brb or something lol
    {
        for(i=0; i<receive.length; i++)        //simple loop, while i less than receive.length [which in this case is 1 (zero based)] adds 1
        {
            if(Message == receive[i])        //if Message is equal to receive[i] (the first time it would be 0 which is brb)
            {
                ChatWnd.SendMessage(send[i]);//sends the message in send[i], this is y they need to match, so if receive[i] & send[i] is 0, it sends "okeydokey"
            }
        }
    }
}

it works, I've tested it :)
RE: im having troble with my script by matty on 08-08-2007 at 12:47 PM

Instead of doing a For Loop for an array like this:

quote:
Originally posted by LifelesS
code:
for(i=0; i<receive.length; i++)

do it like this:
code:
for(var i in arrayname)

RE: im having troble with my script by Volv on 08-08-2007 at 01:01 PM

matty, unless I'm mistaken, that doesn't allow you to get the element's index in the array and hence you can't get the corresponding response =/


RE: im having troble with my script by Matti on 08-08-2007 at 03:19 PM

quote:
Originally posted by Volv
matty, unless I'm mistaken, that doesn't allow you to get the element's index in the array and hence you can't get the corresponding response =/
No, that's why the variable i is there! Actually, it doesn't matter what method you choose, it'll always give you a loop through the array. However, if you're trying this on an object, you have to use Matty's method because an object doesn't have numeral indexes. Instead, the i variable contains the key name of the object value. For example:
code:
var FruitColors = function() {
   this.Banana = "yellow"; //"Banana" is not numeral and therefore you can't use a number to iterate through this object
   this.Apple = "red";
   this.Pear = "green";
}
var MyObject = new FruitColors();
for(var i in MyObject) {
   Debug.Trace("The color of "+i+"s is "+FruitColors[i]); //Output: "The color of Bananas is yellow" etc.
}