Shoutbox

Simple Problem w/ Objects - 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: Simple Problem w/ Objects (/showthread.php?tid=92219)

Simple Problem w/ Objects by Cetanu on 09-15-2009 at 02:34 PM

I am looking to use SendMessage if someone messages me when I am Busy or Away, but I don't know how to create an object of ChatWnd. Could someone please explain what it means (and how to) to create an object of ChatWnd.


I know that creating an object of global things involves something like Messenger.MyName, but I dunno what to do with ChatWnd, and it's driving me crazy. Thanks!


RE: Simple Problem w/ Objects by matty on 09-15-2009 at 02:45 PM

Have a look at this thread for some useful information. Script Always Stopped


RE: Simple Problem w/ Objects by Cetanu on 09-15-2009 at 02:50 PM

That's great! THANKS A LOT!


RE: Simple Problem w/ Objects by matty on 09-15-2009 at 02:58 PM

No problem, glad it cleared up the confusion for you :)


RE: Simple Problem w/ Objects by Cetanu on 09-15-2009 at 05:18 PM

There is one more thing I forgot:

If I were to have a code like this: (outline, not actual code)
if (I am busy){
if(I receive a message){
SendMessage("I'm doing ______");
}
}

That's not the syntax, just the point. :D But how would I do that since SendMessage requires a ChatWnd object... >.> Maybe I just missed it in that thread; I'll read again, but help is still appreciated. :)


Edit: I do think I missed it, since this was the question I asked before, I just forgot that I asked it.


RE: Simple Problem w/ Objects by matty on 09-15-2009 at 05:45 PM

The function OnEvent_ChatWndMessageReceive has a parameter called pChatWnd. This is the Chat Window where the event happened. Therefore you could do something like this:

js code:
var oChatWnds = {}; // variable to hold the chat window handles and the messages we send to make sure we are not sending the message causing infinite loops

function OnEvent_ChatWndSendMessage ( pChatWnd , sMessage )
{
    oChatWnds [ pChatWnd.Handle ] = sMessage; // add the message to the object
}

function OnEvent_ChatWndReceiveMessage ( pChatWnd , sOrigin , sMessage , nMessageKind )
{
    if ( oChatWnds [ pChatWnd.Handle ] === sMessage ) return sMessage; // Since we just send this message we can ignore it
   
    if ( Messenger.MyStatus === STATUS_BUSY ) // check if your status is busy
    {
        pChatWnd.SendMessage ( 'I currently am busy and cannot reply. Thank you for your paitence.' ); // if it is busy then send a message
    }
}

function OnEvent_ChatWndDestroyed ( pChatWnd )
{
    delete oChatWnds [ pChatWnd.Handle ]; // delete the message from our storage object
}

RE: Simple Problem w/ Objects by Cetanu on 09-15-2009 at 06:02 PM

Has anyone referred to you as a deity?

^_^ THANKS! It worked...I wouldn't be able to accomplish that with my knowledge of JS.


RE: Simple Problem w/ Objects by matty on 09-15-2009 at 06:36 PM

No problem it is what we are here for. There have been a lot of discussion surrounding the best way to programmatically tell who sent what message through Plus! Scripting. The sad thing is is that Plus! has no way of knowing the email of the contact; only their name. With that said this is the easiest way of knowing if you sent the message. If the messages do not match well than you know you didn't send it.


RE: Simple Problem w/ Objects by Cetanu on 09-15-2009 at 08:32 PM

Well, thanks. :) I've used this code so much already....XD


RE: Simple Problem w/ Objects by CookieRevised on 11-23-2009 at 09:47 PM

quote:
Originally posted by matty
With that said this is the easiest way of knowing if you sent the message. If the messages do not match well than you know you didn't send it.
Unfortunatly, I see you use that kind of approach in many example codes of yours. Although it would work in theory, it is not implemented properly in any of your example codes and thus will not work properly!

You will get into trouble when the contact sends the same message (at a certain point in time) as you last did:

You: Type the next command to initiate the transfer:
You: !start
Contact: Ah, ok, thanks. I'l send the command now
Contact: !start
Contact: nothing happened :(
You: Hmm, the code in OnEvent_ChatWndReceiveMessage was never executed...
...

^^ the above scenario will show exactly what I mean...

To solve that you must delete oChatWnds[pChatWnd.Handle] before you return with sMessage in OnEvent_ChatWndReceiveMessage
js code:
function OnEvent_ChatWndReceiveMessage(pChatWnd, sOrigin, sMessage, nMessageKind ) {
    if (oChatWnds[pChatWnd.Handle] === sMessage ) {
        >>>delete oChatWnds[pChatWnd.Handle];<<<
        return sMessage; // Since we just send this message we can ignore it
    }
    ...
}

;)