Shoutbox

[Question]Remembering a ChatWnd - 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: [Question]Remembering a ChatWnd (/showthread.php?tid=79974)

[Question]Remembering a ChatWnd by MrR on 12-12-2007 at 06:24 PM

Hey guys ^^
I started scripting in MP!L 2 days ago, and it's all going fine.
Today I tried to script an auto-message thingy, that basically has to send a message in an open chat window after awhile.

So I set a timer id, and a var to contain my message, but my problem is in the 'OnEvent_Timer' function. I just can't seem to create the ChatWnd so I could send the message. I tried saving the contact email and using Messenger.OpenChat, I also tried simply using a ChatWnd without defining. I tried countless variations of anything that refers to creating a ChatWnd in the documentation, and nothing seems to work.
So does anyone know how to save a ChatWnd \ ChatWnd identifier in a Var, so I could re-use it to send messages under the Timer function?

Thank you very much,
Roy.


RE: [Question]Remembering a ChatWnd by Spunky on 12-12-2007 at 07:31 PM

code:
var ChatWnd = Messenger.OpenChat("email@hotmail.com");
ChatWnd.SendMessage(message);


Is that how you tried the code or different?

RE: [Question]Remembering a ChatWnd by MrR on 12-12-2007 at 07:38 PM

That's what I did, replace the email in a var.
I think the problem is in the var, since when I told it to trace it it returned nothing (not null, just a line in the debugger containing NOTHING).

Is there any way to keep the hWnd and start a new chatwnd  with it? That'd make things easier D:


RE: [Question]Remembering a ChatWnd by Spunky on 12-12-2007 at 07:47 PM

When someone talks to you, you can add the chatwnd object to an array, using the chatwnd's handle to identify it...

code:
var myArray = new Array();

function OnEvent_ChatWndRecieveMessage(ChatWnd, Origin, Message){
    myArray[ChatWnd.Handle] = ChatWnd;
}


Then in your timer you can tell it to send a message to all the chatwnds in the array. Obviously, you will want to check that it's specific people unless you want it to send to everybody that sends you a message
RE: [Question]Remembering a ChatWnd by MrR on 12-12-2007 at 08:05 PM

Nevermind, problem solved.
I can't believe, as a programmer in other languages, that my mistake was so newbie (I don't have any background in JS :P)

I just had to set the var to the object itself.. myChat = ChatWnd.
And then use it in the other function.
Thanks alot, tho. Your array helped me think of the answer :)


RE: [Question]Remembering a ChatWnd by Spunky on 12-12-2007 at 08:17 PM

Lol, Glad I could help (in a round-about way)


RE: [Question]Remembering a ChatWnd by CookieRevised on 12-12-2007 at 09:38 PM

Do NOT store the chat window handle, nor the object in a variable when you are going to use it later on.

Chat windows, like any window, can be closed. And closing a window means that your handle will become invalid and the object destroyed.

The proper way to do this is to store the contact's email address instead. When the time has come to send a message, you open up a chat window with that contact. If the 'old' chat window was never closed then it will be used again. If the chat window was closed, a new window will be created.


RE: [Question]Remembering a ChatWnd by MrR on 12-12-2007 at 09:51 PM

But the usage I was looking for is immediate, and I want it, if needed, to send the message to the whole chatting group, and not only one of them.


RE: [Question]Remembering a ChatWnd by CookieRevised on 12-12-2007 at 10:22 PM

quote:
Originally posted by MrR
But the usage I was looking for is immediate
Why are you using timers then? (see your first post)
Also:
quote:
Originally posted by MrR
That basically has to send a message in an open chat window after awhile.

Any delay (even 1 second) means you should not store the handle and the window objects.


quote:
Originally posted by MrR
and I want it, if needed, to send the message to the whole chatting group, and not only one of them.
What do you mean by the "whole chatting group"?
RE: [Question]Remembering a ChatWnd by MrR on 12-13-2007 at 06:06 AM

quote:
Originally posted by CookieRevised
quote:
Originally posted by MrR
But the usage I was looking for is immediate
Why are you using timers then? (see your first post)

Cause I want it to output it several times :)

quote:
Originally posted by CookieRevised
Also:
quote:
Originally posted by MrR
That basically has to send a message in an open chat window after awhile.

Any delay (even 1 second) means you should not store the handle and the window objects.

Well I ensure you that if I'll dispose the window in the middle I won't need the script in a first place. ^^


quote:
Originally posted by CookieRevised
quote:
Originally posted by MrR
and I want it, if needed, to send the message to the whole chatting group, and not only one of them.
What do you mean by the "whole chatting group"?

I mean to all of the people in the same chat window I was using, basically to the same window so whoever in it will see it.
RE: RE: [Question]Remembering a ChatWnd by CookieRevised on 12-13-2007 at 07:47 AM

quote:
Originally posted by MrR
...Cause I want it to output it several times :)

...Well I ensure you that if I'll dispose the window in the middle I won't need the script in a first place. ^^

...I mean to all of the people in the same chat window I was using, basically to the same window so whoever in it will see it.
Again, do not store the window handle!

If you are not sending the message immediatly, for any reason, you should not store the handle but the email address(es) of the contacts.

You will otherwise encounter problems in certain situations. Even if you say you don't close the window yourself.... Before actually using the chatwindow object, you should at the least check if:
a) the window is still there
b) you are able to send a message to the window