It's just a matter of finding a way to retrieve a ChatWnd object through one of the functions or events Plus! Live gives you. When you have a ChatWnd object, you'll have to check if you can send a message first with the ChatWnd.EditChangeAllowed property and then, you can send a message to it.
I'll give you one example about how you should find such things out.
quote:
Originally posted by flashmaniac
You can send a message when a chat window is created by using the ChatWnd parameter of OnEvent_ChatWndCreated.
- The scripting documentation is your best friend! Look up the event!
quote:
Scripting Documentation > Events > Messenger Events > OnEvent_ChatWndCreated
The OnEvent_ChatWndCreated event is fired when a new chat window is created.
Syntax
code:
OnEvent_ChatWndCreated(
[object] ChatWnd
);
- Now we know how our function declaration should be built. Plus! Live will try to find a function called OnEvent_ChatWndCreated in your script and when a chat window is created, it'll send a ChatWnd object as parameter to your function. Using this information, you can already built this event in your script:
code:
function OnEvent_ChatWndCreated(oChatWnd) {
//oChatWnd will be a ChatWnd object for the chat window that was created
}
- Because we want to send a message when the chat window is created, we'll need to know more about the ChatWnd.SendMessage() function. The scripting documentation says this:
quote:
Scripting Documentation > Objects > ChatWnd Object > SendMessage
The ChatWnd::SendMessage function sends a message to the contacts currently present in the chat window.
Syntax
code:
[boolean] SendMessage(
[string] Message
);
Return Value
If the message is sent successfully, the return value is true, else, the return value is false.
...
Remarks
...
The EditChangeAllowed property should be checked before this function is called.
- Now we know that the SendMessage function accepts one parameter Message of the type string, which means that it's a literal value. The return value of the function is a boolean value (true or false) defining if the function succeeded in sending the message or not. This value is important because you can't always be sure if the message was actually sent, since there are cases where Plus! can't send it. One of these cases is that the chat window was destroyed, but that would be very unlikely because in our case of OnEvent_ChatWndCreated, it was just created! However, in a serious script, you should take every possibility in account, but I won't go about that now. The other case is that the typing area is disabled because the contact has been blocked by the user. Therefore, the remarks state that you should first check if the ChatWnd.EditChangeAllowed property is set to true. Only then you know you can send a message. This brings us to the final piece of code:
code:
function OnEvent_ChatWndCreated(oChatWnd) {
if(oChatWnd.EditChangeAllowed) { //Check if the typing area is available
var Result = oChatWnd.SendMessage("Hello there!"); //Send the message
Debug.Trace("SendMessage returned: "+Result); //Send the result to the script debugger, if you want to check if everything went right
}
}
And with this way too long manual, you should be able to find out the other things yourself! Because that's what scripting (and programming in general) is all about: combine the things you need in such a way that you can get the right result.