Question about "MyStatus" |
Author: |
Message: |
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: Question about "MyStatus"
quote: Originally posted by matty
...
I prefer to use the enumeration for status
Of course, but that would break backwards compatibility. And it'll save you a few bytes.
...
Okay perhaps it's not so much of a big deal. Choose whatever you think is best.
This post was edited on 01-19-2010 at 04:55 PM by Matti.
|
|
01-19-2010 04:55 PM |
|
|
5n4k3
Junior Member
Posts: 18 Reputation: 1
30 / /
Joined: Jan 2010
|
O.P. RE: Question about "MyStatus"
Mmm... so is stoshrocket's solution to my auto-message problem the best way?
And if so what's the line:
javascript code: if(automsg == -1)
do?
~ 5n4k3
|
|
01-19-2010 05:20 PM |
|
|
stoshrocket
Senior Member
formerly methos
Posts: 748 Reputation: 31
34 / /
Joined: Aug 2005
|
RE: Question about "MyStatus"
quote: Originally posted by 5n4k3
And if so what's the line:
javascript code: if(automsg == -1)
do?
The variable automsg is the return value for "Message.search("AutoMessage :")".
search() returns the position what is searched for, or -1 if it can't be found.
Therefore, that line checks if "AutoMessage :" is in the message sent, if it is then it's (probably) an automessage and won't change your status. Of course, this will trip up if your message sent contains the string "AutoMessage :".
This post was edited on 01-19-2010 at 07:54 PM by stoshrocket.
|
|
01-19-2010 07:52 PM |
|
|
CookieRevised
Elite Member
Posts: 15517 Reputation: 173
– / /
Joined: Jul 2003
Status: Away
|
RE: Question about "MyStatus"
shorter and slithly faster: js code: function OnEvent_ChatWndSendMessage( ChatWnd, Message )
{
// Check if it is not an automessage and if we're not busy yet
if (!/^AutoMessage :/.test(Message) && Messenger.MyStatus !== 4 ) {
// Set to busy
Messenger.MyStatus = 4;
}
// Return the unmodified message
// Never forget to return something for ChatWndSendMessage!
return Message;
}
! means NOT (The boolean True becomes False, and False becomes True)
/blahblah/ is a special syntax used for regular expressions
^ at the beginning of a regular expression means start comparing it from the beginning (aka: don't do a (slower) search).
test(blahblah) is a method of the regular expression object which test the occurance of the regular expression (in the above case '^AutoMessage :') in the string (in the above case the Message variable)
&& performs a logical conjunction (=AND) on two expressions (both expressions must be True for the result to be True)
If Message begins with the string 'AutoMessage :' then /^AutoMessage :/.test(Message) will return True. Otherwise it will return False. Hence the use of ! (=NOT) to change the result of the test to the opposite...
This post was edited on 01-19-2010 at 08:45 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
|
|
01-19-2010 08:35 PM |
|
|
roflmao456
Skinning Contest Winner
Posts: 955 Reputation: 24
30 / /
Joined: Nov 2006
Status: Away
|
RE: Question about "MyStatus"
there is no space before the colon - only after.
it should be searching for "AutoMessage: "
your full script:
JScript code: var szStatus = {
2 : "appear offline",
3 : "online",
4 : "busy",
7 : "away",
6 : "idle",
// maybe it can happen
0 : "unknown",
// WLM 8.5
5 : "brb",
8 : "in a call",
9 : "out to lunch"
};
function OnEvent_ChatWndCreated(ChatWnd){
MsgPlus.DisplayToast("", "Your Messenger Status: " + szStatus[Messenger.MyStatus]);
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if(Messenger.MyStatus !== STATUS_BUSY && !/^AutoMessage: /.test(Message))
Messenger.MyStatus = STATUS_BUSY;
}
@cookiematty: that enumeration for status code you posted returns undefined if like variable[MyStatus]. using it like variable.STATUS_ONLINE will work, however.
This post was edited on 01-20-2010 at 02:47 AM by roflmao456.
[quote]
Ultimatess6: What a noob mod
|
|
01-19-2010 10:58 PM |
|
|
CookieRevised
Elite Member
Posts: 15517 Reputation: 173
– / /
Joined: Jul 2003
Status: Away
|
RE: Question about "MyStatus"
quote: Originally posted by roflmao456
@cookie: that enumeration for status code you posted returns undefined if like variable[MyStatus]. using it like variable.STATUS_ONLINE will work, however.
blame matty, he posted it, not me
.-= A 'frrrrrrrituurrr' for Wacky =-.
|
|
01-19-2010 11:39 PM |
|
|
roflmao456
Skinning Contest Winner
Posts: 955 Reputation: 24
30 / /
Joined: Nov 2006
Status: Away
|
|
01-20-2010 02:47 AM |
|
|
5n4k3
Junior Member
Posts: 18 Reputation: 1
30 / /
Joined: Jan 2010
|
O.P. RE: Question about "MyStatus"
Thanks guys, it works great.
~ 5n4k3
|
|
01-20-2010 11:20 AM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: Question about "MyStatus"
quote: Originally posted by CookieRevised
quote: Originally posted by roflmao456
@cookie: that enumeration for status code you posted returns undefined if like variable[MyStatus]. using it like variable.STATUS_ONLINE will work, however.
blame matty, he posted it, not me
Ah yes, you can't use the value of a variable or expression as identifier for a property when you're defining an object literal. "STATUS_ONLINE" is interpreted as a string identifier for the property, it does not take the value of STATUS_ONLINE to use as identifier.
Here are some example snippets, for those interested in what went wrong here: js code: var key = "123";
var obj = {
key : "abc"
};
// obj.key or obj["key"] equals "abc"
// obj[key] is undefined
var obj = {
"key" : "abc"
};
// same object as above
var i = 0;
var obj = {
(i++) : "first",
(i++) : "second"
};
// gives a syntax error
// property identifier must be a constant number or string
var i = 0;
var obj = {};
obj[i++] = "first";
obj[i++] = "second";
// this will work though, the square brackets can take both constant or variable values
|
|
01-20-2010 12:27 PM |
|
|
Pages: (2):
« First
«
1
[ 2 ]
Last »
|
|