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

Pages: (2): « First [ 1 ] 2 » Last »
Question about "MyStatus"
Author: Message:
5n4k3
Junior Member
**


Posts: 18
Reputation: 1
30 / Male / Flag
Joined: Jan 2010
O.P. Question about "MyStatus"
I wrote this rather pointless script (just practicing) and it works, but there's something I wanted to ask if you could change.

Here's the Script:
function OnEvent_ChatWndCreated(ChatWnd)
{
    var Message = "Your current status is " + Messenger.MyStatus + "!";
    Message = MsgPlus.RemoveFormatCodes(Message);
    MsgPlus.DisplayToast("", Message)
}

I was wondering if you could make it say in the message your actual status (i.e. "busy" | "online" | "away" | etc) instead of using the numbers associated with each status.

EDIT: I'm also failing to write a script that changes my status to busy every time I send a message if I'm not already set as busy.  So far I came up with this...:
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
    if(MyStatus == (7))
    {
    var Message = "/busy";
    Message = MsgPlus.RemoveFormatCodes(Message);
    Messenger.ChatWnd.SendMessage
    }
}
^ guessed a lot

Thanks

~ 5n4k3

This post was edited on 01-17-2010 at 06:21 PM by 5n4k3.
01-17-2010 06:01 PM
Profile E-Mail PM Find Quote Report
stoshrocket
Senior Member
****

Avatar
formerly methos

Posts: 748
Reputation: 31
34 / Male / Flag
Joined: Aug 2005
RE: Question about "MyStatus"
quote:
Originally posted by 5n4k3
I wrote this rather pointless script (just practicing) and it works, but there's something I wanted to ask if you could change.

Here's the Script:
function OnEvent_ChatWndCreated(ChatWnd)
{
    var Message = "Your current status is " + Messenger.MyStatus + "!";
    Message = MsgPlus.RemoveFormatCodes(Message);
    MsgPlus.DisplayToast("", Message)
}

I was wondering if you could make it say in the message your actual status (i.e. "busy" | "online" | "away" | etc) instead of using the numbers associated with each status.
Use a loop and a couple of arrays to replace the number?

javascript code:
function OnEvent_ChatWndCreated(ChatWnd)
{
    var Message = "Your current status is " + Messenger.MyStatus + "!";
    var number = new Array("2","3","4","5"....);
    var status = new Array("Appear Offline","Online","Busy","Be Right Back"....);
    for(var i = 0; i<number.length; i++){
        Message = Message.replace(number[i],status[i]);
    }
    Message = MsgPlus.RemoveFormatCodes(Message);
    MsgPlus.DisplayToast("", Message)
}

EDIT: Sorry, had a few errors, should work fine now... As for the second question, I'll answer shortly...

This post was edited on 01-17-2010 at 07:21 PM by stoshrocket.
formerly methos
01-17-2010 06:29 PM
Profile PM Web Find Quote Report
5n4k3
Junior Member
**


Posts: 18
Reputation: 1
30 / Male / Flag
Joined: Jan 2010
O.P. RE: Question about "MyStatus"
Thanks for that, btw is there a place where I can learn about "arrays", etc?
01-17-2010 07:24 PM
Profile E-Mail PM Find Quote Report
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
stoshrocket
Senior Member
****

Avatar
formerly methos

Posts: 748
Reputation: 31
34 / Male / Flag
Joined: Aug 2005
RE: Question about "MyStatus"
Much better solution Matti, thanks :P
formerly methos
01-17-2010 08:10 PM
Profile PM Web Find Quote Report
5n4k3
Junior Member
**


Posts: 18
Reputation: 1
30 / Male / Flag
Joined: Jan 2010
O.P. RE: Question about "MyStatus"
Ah thanks guys. Lots to learn... gonna be interesting.

Hmm... I was just thinking... if both ways work why is Matti's way better?

This post was edited on 01-17-2010 at 08:30 PM by 5n4k3.
01-17-2010 08:24 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Question about "MyStatus"
Because it does not use a very slow, and completely unneeded, loop. Nor does it need two arrays being stored in memory.

Image what would happen if there are 10000 elements you need to index. Your script would run so slow you would think it has been froozen/crashed.

stoshrocket's script did this:
code:
1) Make a list of names:
    number 1 is BlahBlah
    number 2 is BooBoo
    number 3 is HeyHey

2) Make a list of numbers/indexes
    number 1 is 1
    number 2 is 2
    number 3 is 3

3) Change the list of numbers into a list of names
    Check if the index is still within the bounds of the number list
    if so, lookup name 1 and store it in memory
    Replace index 1 with the value stored in memory
    increase the index by one
    Check if the index is still within the bounds of the number list
    if so, lookup name 2 and store it in memory
    Replace index 2 with the value stored in memory
    increase the index by one
    Check if the index is still within the bounds of the number list
    if so, lookup name 3 and store it in memory
    Replace index 3 with the value stored in memory
    increase the index by one
    Check if the index is still within the bounds of the number list
    if so, ...., if not end the loop

4) Look up the current status

5) Get the correct name in the list of numbers.
So, even if you used an array, you can see that there is really no need for two arrays. The array in step 2 is completely useless because you already have all the names in order in the first array. Making the loop also useless. The second array is simply a list of its own indexes (an index is the number which defines an element of the array).

Matti's script does this:
code:
1) Make a list of status names, indexed and sorted by their literal numeric value: blahblah, BooBoo, HeyHey
2) Look up the current status
3) Get the correct status name in the list of statusses
Matti simply uses Messenger.MyStatus to get the proper element directly from the list.

This is possible since the numeric values of Messenger.MyStatus are known and always the same.

eg: Messenger.MyStatus will always return the number 2 when you are appearing offline. So simply grab the third (counting starts at 0) element out of the predefined string list.



It's like:

You have a piece of paper showing a number  (= Messenger.MyStatus) which tells you behind what curtain your prize (= your status strings like "offline", "online", etc) is.

stoshrocket's method:

First, construct a bunch of curtains and put some prizes behind it.

Second, construct a bunch of new doors and put a new piece of paper behind it like so:
Door 1, instructon on the new piece of paper: open curtain 1
Door 2, instructon on the new piece of paper: open curtain 2
Door 3, instructon on the new piece of paper: open curtain 3
etc..
this is the loop

Next, open the door with the number listed on your original piece of paper.
Then, open the curtain instructed on that new piece of paper you've found behind the door you've opened....

But did you notice how all those doors have the exact same number as the number in the instructions of those new pieces of paper behind each door?

Thus Matti's method:

First, construct a bunch of curtains and put some prizes behind it.
Second, directly open the curtain with the number that is on your original piece of paper....


^^ sorry for the long post, I was bored
:p

This post was edited on 01-17-2010 at 11:00 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-17-2010 10:26 PM
Profile PM Find Quote Report
5n4k3
Junior Member
**


Posts: 18
Reputation: 1
30 / Male / Flag
Joined: Jan 2010
O.P. RE: Question about "MyStatus"
I came across another problem with the script:

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;
}

When my auto-message responds it changes my status to busy. How do I fix that?

EDIT: Spent some time on it and I'm thinking I should use something like

js code:
{
if(Message == "<insert my auto-message>"
Messenger.MyStatus = 7;
}

But it doesn't work.

~ 5n4k3

This post was edited on 01-19-2010 at 01:08 PM by 5n4k3.
01-19-2010 08:19 AM
Profile E-Mail PM Find Quote Report
stoshrocket
Senior Member
****

Avatar
formerly methos

Posts: 748
Reputation: 31
34 / Male / Flag
Joined: Aug 2005
RE: Question about "MyStatus"
quote:
Originally posted by 5n4k3
I came across another problem with the script:

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;
}

When my auto-message responds it changes my status to busy. How do I fix that?

EDIT: Spent some time on it and I'm thinking I should use something like

js code:
{
if(Message == "<insert my auto-message>"
Messenger.MyStatus = 7;
}

But it doesn't work.

~ 5n4k3
When the auto message is sent, messenger appears to see it as it being sent in the format "AutoMessage: <automessage>" (test it yourself by creating a toast to popup with every message you send, when "you" send an automessage, it comes up in this format). Therefore, a possible solution would be to check if the message sent starts with "AutoMessage: " ...

javascript code:
function OnEvent_ChatWndSendMessage( ChatWnd, Message )
{
    //search message for "AutoMessage :"
    var automsg = Message.search("AutoMessage :");
    if(automsg == -1){
        // 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;
}

Note: this would just check if your message has "AutoMessage :" in, so if you typed a message with this in it obviously would pick it up, so a better solution might be to check the position?

Still, it's not the most elegant of solutions... As Matti proved earlier there's more than one way to solve a problem.
formerly methos
01-19-2010 02:55 PM
Profile PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Question about "MyStatus"
quote:
Originally posted by Matti
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"
};


:dodgy:...
I prefer to use the enumeration for status
js code:
// On the top of your script, outside any function definition
var oStatusNames = {
    STATUS_UNKNOWN:    'unknown',
    STATUS_INVISIBLE:    'appearing offline',
    STATUS_ONLINE:    'online',
    STATUS_BUSY:        'busy',
    STATUS_BRB:        'be right back',
    STATUS_IDLE:        'idle',
    STATUS_AWAY:        'away',
    STATUS_INCALL:    'in a call',
    STATUS_OUTLUNCH:    'out to lunch'
};
01-19-2010 03:29 PM
Profile E-Mail PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


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