What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Question about "MyStatus"

Question about "MyStatus"
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Question about "MyStatus"
quote:
Originally posted by stoshrocket
Use a loop and a couple of arrays to replace the number?
Don't do this. There is absolutely no need for a loop to simply show the name of the current status, you can perfectly achieve this with an object literal indexed by the status number. Using arrays for this is totally unnecessary since we only need the ability to look up a certain property value (the name) by its identifier (the number).
js code:
// On the top of your script, outside any function definition
var oStatusNames = {
    0:    "unknown",
    2:    "appearing offline",
    3:    "online",
    4:    "busy",
    5:    "be right back",
    6:    "idle",
    7:    "away",
    8:    "in a call",
    9:    "out to lunch"
};

// The fixed event handler for chat window created
function OnEvent_ChatWndCreated( ChatWnd )
{
    // Find the name of the current status in our object   
    var status = oStatusNames[ Messenger.MyStatus ];
    // Make a nice message
    var message = "Your current status is " + status + "!";
    // Display a toast
    MsgPlus.DisplayToast( "Your current status", message );
}
As you can see, there's no need for looping through one array and replace all numbers by their status names: you perfectly know what status number you're looking for as you're building the message yourself! There's also no real necessity for calling MsgPlus.RemoveFormatCodes() when you don't add any format codes in the message. Of course, when the message could have been set by the user through some kind of script preference, you're better off removing the format codes, but in this simple example I chose not to.



As for setting your status, you can simply set Messenger.MyStatus yourself, it's not read-only:
js code:
function OnEvent_ChatWndSendMessage( ChatWnd, Message )
{
    // See if I'm not busy yet
    if( Messenger.MyStatus !== 4 ) {
        // Set to busy
        Messenger.MyStatus = 4;
    }
    // Return the unmodified message
    // Never forget to return something for ChatWndSendMessage!
    return Message;
}


quote:
Originally posted by 5n4k3
Thanks for that, btw is there a place where I can learn about "arrays", etc?
I highly recommend learning some JScript/JavaScript if you want to write Plus! scripts. There are many places to learn this, but perhaps the W3Schools tutorials are best suited for newcomers. Just beware that you're not programming in a website environment, so anything related to the place of your script in the HTML or the Document Object Model is not available in a Plus! script. Other than that, the syntax of JavaScript is as good as identical to JavaScript's syntax, therefore it's a very good starting point. :)

Arrays may not be ideal for this example (see above), but they're very interesting to work with. Basically, an array is a numbered list of stuff in which you can add, read, change and remove elements. Have a look at the W3Schools topics on arrays, that'll probably help you understand. ;)

This post was edited on 01-20-2010 at 12:18 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
01-17-2010 07:56 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Question about "MyStatus" - by 5n4k3 on 01-17-2010 at 06:01 PM
RE: Question about "MyStatus" - by stoshrocket on 01-17-2010 at 06:29 PM
RE: Question about "MyStatus" - by 5n4k3 on 01-17-2010 at 07:24 PM
RE: Question about "MyStatus" - by Matti on 01-17-2010 at 07:56 PM
RE: Question about "MyStatus" - by stoshrocket on 01-17-2010 at 08:10 PM
RE: Question about "MyStatus" - by 5n4k3 on 01-17-2010 at 08:24 PM
RE: Question about "MyStatus" - by CookieRevised on 01-17-2010 at 10:26 PM
RE: Question about "MyStatus" - by 5n4k3 on 01-19-2010 at 08:19 AM
RE: Question about "MyStatus" - by stoshrocket on 01-19-2010 at 02:55 PM
RE: Question about "MyStatus" - by matty on 01-19-2010 at 03:29 PM
RE: Question about "MyStatus" - by Matti on 01-19-2010 at 04:55 PM
RE: Question about "MyStatus" - by 5n4k3 on 01-19-2010 at 05:20 PM
RE: Question about "MyStatus" - by stoshrocket on 01-19-2010 at 07:52 PM
RE: Question about "MyStatus" - by CookieRevised on 01-19-2010 at 08:35 PM
RE: Question about "MyStatus" - by roflmao456 on 01-19-2010 at 10:58 PM
RE: Question about "MyStatus" - by CookieRevised on 01-19-2010 at 11:39 PM
RE: Question about "MyStatus" - by roflmao456 on 01-20-2010 at 02:47 AM
RE: Question about "MyStatus" - by 5n4k3 on 01-20-2010 at 11:20 AM
RE: Question about "MyStatus" - by Matti on 01-20-2010 at 12:27 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On