Shoutbox

Script Snippit Examples? - 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 Snippit Examples? (/showthread.php?tid=85742)

Script Snippit Examples? by Keikonium on 09-02-2008 at 11:22 PM

Is there a place on the net where I can view examples of code with an explanation of what it does? Basically, I am a noob when it comes to JScript, and I'm not quite understanding the documentation all the well :-#.

For example, I see in the documentation for the "MsgPlus:: PlaySound" syntax. To call this function, I type "MsgPlus.PlaySound(syntax)". So what I see happening, is changing the "::" in the documentation to a single "." .

When I try to do this same thing with "Contact::Email" changing it to "Contact.Email" it gives me an error in the debug console (Error: 'Contact' is undefined (code: -2146823279)).

So I have no idea what I am doing wrong, and I don't understand why the documentation doesn't include an example or two for each property / function.

If anyone can shed some light on this for me, I'd be happy lol.

Thanks :)


RE: Script Snippit Examples? by Spunky on 09-02-2008 at 11:32 PM

Objects related to Plus! only have the documentation you have seen.

The problem you have is because Contact is an object returned by another function such as GetContact or an enumeration of Messenger.MyContacts


RE: Script Snippit Examples? by Keikonium on 09-02-2008 at 11:42 PM

I'm still a bit confused, so how do I go about calling the objects that aren't related to Plus!?

I have tried "Contacts.GetContact(Email);" (which makes sense to me) but I still get an error :P.

I just want to display a toast that contains a contacts email when they sign in lol.

This is the code I am using:

code:
var contactMail = Contacts.GetContact(Email);
var contactName = Contacts.GetContact(Name);

// PLAYS A SOUND WHEN A CONTACT SIGNS IN
function OnEvent_ContactSignin(){
MsgPlus.DisplayToastContact("Sign In","" + contactName + "", "(" + contactMail + ")\nhas signed in.", "", "OnEvent_ToastClicked", contactMail);
}


I can get the toasts to display fine if I make the vars into text strings (just adding " and " around whatever I have there) so I know there is no problem with the toast code, it's just the vars and such.
RE: Script Snippit Examples? by matty on 09-02-2008 at 11:56 PM

Well first things first take a look at the documentation.

code:
OnEvent_ContactSignin(
        [string] Email
    );

Notice the function passes the email address as a parameter. Therefore the code you use is

code:
function OnEvent_ContactSignin(sEmail){
    Debug.Trace(sEmail);
}

Also to note that the Contact and Contacts objects are only available when you enumerate or use the Messenger.MyContacts.GetContact function.

To enumerate the object you need to do the following:

code:
for ( var oContact = new Enumerator(Messenger.MyContacts); !oContact.atEnd(); oContact.moveNext() );
    Debug.Trace( oContact.item().Email );
}

And to use the GetContact function it looks like this
code:
Debug.Trace( Messenger.MyContacts.GetContact( 'johndoe@hotmail.com' ).Email );

RE: Script Snippit Examples? by Matti on 09-03-2008 at 11:09 AM

To continue on matty's post:

Since you already have the Email parameter passed to your OnEvent_Signin function, you can use that to get a Contact object for the contact who just signed in. We'll store that in a variable, such as "theContact". Then, we have a valid Contact object so we can use all of its functions and properties. The one we are interested in is the contact's name, so we make a variable "sName" to store the contact's display name in. From there, you can easily use the "sEmail" and "sName" to display a toast.

code:
function OnEvent_ContactSignin(sEmail){
    var theContact = Messenger.MyContacts.GetContact(sEmail);
    var sName = theContact.Name;
    MsgPlus.DisplayToastContact("Sign In","" + sName + "", "(" + sEmail + ")\nhas signed in.", "", "OnEvent_ToastClicked", sEmail);
}
Since you defined a callback function "OnEvent_ToastClicked" in that call, you might want to make such a function:
code:
function OnEvent_ToastClicked(sEmail) {
    //Do something useful here!
}

RE: Script Snippit Examples? by Keikonium on 09-03-2008 at 11:19 AM

Ah it works :D! I think I understand this now, since I've applied it to contacts starting a conversation also :).

Thanks for helping out a noob guys, it's been quite informative ^_^.

I hope to get my script out soon (almost done the basics!).


RE: Script Snippit Examples? by Ezra on 09-03-2008 at 02:05 PM

Snippets:

http://mpscripts.net/code.php


RE: Script Snippit Examples? by Keikonium on 09-03-2008 at 06:07 PM

That's the first site I came across when I searched before I posted. It's got very few examples unfortunately :(


RE: Script Snippit Examples? by matty on 09-03-2008 at 06:21 PM

Dempsey is kind of busy and it takes a lot to contribute to something that bug and complex.