What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » If statements and editing a script

If statements and editing a script
Author: Message:
vanillaflavoured
New Member
*


Posts: 8
34 / Male / Flag
Joined: Sep 2008
O.P. If statements and editing a script
Okay so I'm making some changes to a script (for personal reasons) which changes the first letter of a string to uppercase and adds a full stop to the end of the string.

This was all very well and if the string always had to end in a full stop but if I type something like "help!" the result would be "Help!." so I managed to get the script to, by default, add a full stop unless I added one myself or some other form of punctuation.

However my problem is I only want it to uppercase if there is actually a character a-z or A-Z as the first character as when I type Japanese characters it messes the first character up and if I try to send Messenger Plus commands like /busy or /all it creates problems with that too.

Soo yeah...any suggestions?

I've tried switches/case selects and if statements.

:@ If I were able to code in VB/VBA then I'd be fine. Damn Javascript.

So yeah...answers on a postcard?
09-22-2008 09:43 PM
Profile E-Mail PM Find Quote Report
Jesus
Scripting Contest Winner
****

Avatar
Koffie, my cat ;)

Posts: 623
Reputation: 15
38 / Male / Flag
Joined: Jul 2005
RE: If statements and editing a script
Actually, it's not javascript, it's Jscript (though they have many things in common).
As for your problem: If you can code in VB, you must have heard of regular expressions. They can also be used in Jscript, though I'm not sure how they handle the japanese characters.
Man is least himself when he is in his own person. Give him a mask and he will tell you the truth. (Oscar Wilde)
09-23-2008 01:58 AM
Profile PM Find Quote Report
Burningmace
Junior Member
**


Posts: 20
Joined: Sep 2008
RE: If statements and editing a script
code:
function startsWithAlpha(message) {
    if(message.length == 0) { return false; }
    var alpha = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
    var firstChar = message.charAt(0);
    for(i = 0; i < alpha.length; i++) {
        if(alpha.charAt(i) == firstChar) {
            return true;
        }
    }
    return false;
}

This *should* work but I've not tested it and I've not coded in JS for ages.

This post was edited on 09-23-2008 at 11:47 PM by Burningmace.
09-23-2008 11:47 PM
Profile E-Mail PM Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
30 / Male / Flag
Joined: Nov 2006
Status: Away
RE: If statements and editing a script
quote:
Originally posted by Burningmace
code:
function startsWithAlpha(message) {
[...]
}

can be reduced to one line using regexp :)
code:
function startsWithAlpha(message){
    return /^[A-Za-z]/.test(message);
    }
i'm not a master of reg exp so it might have some errors.. lol :P


quote:
Originally posted by vanillaflavoured
Okay so I'm making some changes to a script (for personal reasons)
*cough*punctuator*cough* :P.
quote:
However my problem is I only want it to uppercase if there is actually a character a-z or A-Z as the first character as when I type Japanese characters it messes the first character up and if I try to send Messenger Plus commands like /busy or /all it creates problems with that too.
the code above should fix that.
code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if(startsWithAlpha(message)){
Message = "$" + Message.substr(1);
}
}
/*If I send 'LOL', it will output as '$OL'*/

This post was edited on 09-24-2008 at 12:26 AM by roflmao456.
[quote]
Ultimatess6
: What a noob mod
09-24-2008 12:13 AM
Profile PM Web Find Quote Report
Burningmace
Junior Member
**


Posts: 20
Joined: Sep 2008
RE: If statements and editing a script
To uppercase the first character after you've detected that the fist character is indeed within the range a-Z you can do this:

code:
message = message.charAt(0).toUpper() + message.substr(1);
09-24-2008 12:46 AM
Profile E-Mail PM Find Quote Report
vanillaflavoured
New Member
*


Posts: 8
34 / Male / Flag
Joined: Sep 2008
O.P. RE: RE: If statements and editing a script
quote:
Originally posted by Burningmace
To uppercase the first character after you've detected that the fist character is indeed within the range a-Z you can do this:

code:
message = message.charAt(0).toUpper() + message.substr(1);


This bit I had already sorted out.

Basically, here's what I already have and yes I know this all could probably be done MUCH more simply but like I said, I normally program databases in VB so I have NO experience with JScript etc.

code:
function OnEvent_ChatWndSendMessage(pChatWnd, Message){

var endChar = Message.charAt(Message.length-1)

switch (endChar)
{
case "!":
  endChar = ""
  break;
case "?":
  endChar = ""
  break;
case ".":
  endChar = ""
  break;
case ")":
  endChar = ""
  break;
case ":":
  endChar = ""
  break;
default:
  endChar = "."
}

Message = Message.substr(0,1).toUpperCase() + Message.substr(1) + endChar
    return Message; 

}
09-24-2008 12:20 PM
Profile E-Mail PM Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
30 / Male / Flag
Joined: Nov 2006
Status: Away
RE: If statements and editing a script
quote:
Originally posted by vanillaflavoured
code:
function OnEvent_ChatWndSendMessage(pChatWnd, Message){
[...]
}

shortened:
code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if(/[a-z\d]$/i.test(Message)) Message += ".";
return Message.charAt(0).toUpperCase() + Message.substr(1);
}

;)
[quote]
Ultimatess6
: What a noob mod
09-24-2008 07:55 PM
Profile PM Web Find Quote Report
vanillaflavoured
New Member
*


Posts: 8
34 / Male / Flag
Joined: Sep 2008
O.P. RE: If statements and editing a script
It's still not letting me use the Messenger Plus command though.

However it will let me use custom commands introduced by other scripts. I just can't use the default ones...:S

I'm not sure if it's directly related to this script I'm trying to write though but if I deactivate it, it starts working then...soo...
09-25-2008 10:41 AM
Profile E-Mail PM Find Quote Report
Jesus
Scripting Contest Winner
****

Avatar
Koffie, my cat ;)

Posts: 623
Reputation: 15
38 / Male / Flag
Joined: Jul 2005
RE: If statements and editing a script
That's because the code roflmao456 posted also adds a full stop to any commands you type. This should work:
code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if(/[a-z\d]$/i.test(Message) && Message.charAt(0) != "/") Message += ".";
return Message.charAt(0).toUpperCase() + Message.substr(1);
}
Man is least himself when he is in his own person. Give him a mask and he will tell you the truth. (Oscar Wilde)
09-25-2008 10:53 AM
Profile PM Find Quote Report
vanillaflavoured
New Member
*


Posts: 8
34 / Male / Flag
Joined: Sep 2008
O.P. RE: If statements and editing a script
Cheers guys. Think that's done it. Everything seems to be working great. :D

This post was edited on 09-25-2008 at 11:29 AM by vanillaflavoured.
09-25-2008 11:22 AM
Profile E-Mail PM Find Quote Report
« 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