Shoutbox

[Release] Capitals and full stops(Updated!)V1.1 - 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: [Release] Capitals and full stops(Updated!)V1.1 (/showthread.php?tid=66567)

[Release] Capitals and full stops(Updated!)V1.1 by Jimbo on 09-23-2006 at 04:42 PM

Well, this is my first script
What it does is put a capital letter at the beggining of the message, and also then puts a full stop at the end.
It can be toggled on/off.

Big thanks to jay_jay for coding help

Screenshots:

[Image: 4fz55b6.jpg]
[Image: 2v8o9dw.jpg]
Version log
V1.1 - New UI and will not send the full stop when there is a '?' '.' ',' ';' ':' '!'
V1    - First release


RE: [Release] Capitals and full stops by Chris4 on 09-23-2006 at 05:06 PM

Nice work :)

Suggestion:
Tick/untick the capital letter/false stop, so you can only use one if you want.

Edit: And another..
Ignore the false stop if '?' '!' ':' ';' etc. is at the end of your message.
Otherwise you get "Hello!."


RE: [Release] Capitals and full stops by Jimbo on 09-23-2006 at 05:08 PM

good idea, will try to do it don't hold me to it though as it is my first script


RE: [Release] Capitals and full stops by Zahid™ on 09-23-2006 at 06:39 PM

Already a script that does this: http://www.msgpluslive.net/scripts/browse/index.php?act=view&id=35


RE: [Release] Capitals and full stops by Jimbo on 09-24-2006 at 07:00 AM

oh damn, well mines going to have a UI and also some extra features. hopefully it will be better than that 1

Just to let everyone know whats going to be in the next update:

-there will be a new GUI
-it will ignore the "." if there is a ?,! etc
-and hopefully i will be able to add the feature of doing alternate caps and lower case like this: HeLlO

sorry for double posting


RE: [Release] Capitals and full stops by NanaFreak on 10-01-2006 at 07:38 AM

Ok there is a new release of Capitals and Full Stops for you all :cheesy:

New Features:
The Fulls Stop wont apply when there is a '?' '.' ',' ';' ':' '!'
The Capitals and Full Stops can be on at different times (eg. caps on while full stops off) or at the same time

I hope you enjoy v1.1 of Capitals and Full Stops

see first post :D


RE: [Release] Capitals and full stops(Updated!)V1.1 by xxhannahxx on 10-20-2006 at 07:31 PM

Kool scipt Jimbodude and Nanafreak, maybe you could make the whole message uppercase?


RE: [Release] Capitals and full stops(Updated!)V1.1 by Jimbo on 10-20-2006 at 07:33 PM

Ok, good idea, will do it in the next update


RE: [Release] Capitals and full stops(Updated!)V1.1 by Baggins on 10-20-2006 at 09:02 PM

wtf is a full stop?


RE: [Release] Capitals and full stops(Updated!)V1.1 by prashker on 10-20-2006 at 09:06 PM

quote:
Originally posted by billboy1001
wtf is a full stop?

.
RE: [Release] Capitals and full stops(Updated!)V1.1 by Baggins on 10-20-2006 at 10:45 PM

:$oh:$


RE: [Release] Capitals and full stops(Updated!)V1.1 by CookieRevised on 10-21-2006 at 03:02 AM

quote:
Originally posted by Zahid™
Already a script that does this: http://www.msgpluslive.net/scripts/browse/index.php?act=view&id=35

I don't call that a script tbh. It consist of only 1 line, doesn't check for anything at all. It will screw up commands, etc, etc. Never should have been put in the database IMO. Even JimboDude's first draft of his first script is better than that.



JimboDude

I'll comment on various things so you know where things can be improved and why, so you can apply those things in your future scripts too.

As further reference I suggest to read the Official JScript 5.6 reference in the msdn library and/or download the Official Scripting Documentation from Windows.

Terms in italic in this post can be found in those references, look them up ;)


Anyways:

code:
if (Message.substr((Message.length)-('?'.length)) == '?' || Message.substr((Message.length)-('!'.length)) == '!' || Message.substr((Message.length)-(':'.length)) == ':' || Message.substr((Message.length)-('.'.length)) == '.' || Message.substr((Message.length)-(';'.length)) == ';' || Message.substr((Message.length)-(','.length)) == ',') {
You can simplify all that....

No need for calculating the length of "?", "!", etc... it's always 1 anyways
thus:
code:
Message.substr((Message.length)-1)
"something-1" can be written as "--something", thus:
code:
Message.substr(--Message.length)
Don't use substr to grab 1 character inside a string, use charAt instead:
code:
Message.charAt(--Message.length)


Instead of grabbing the last character each time again, assign the last character to a variable and compare that variable with whatever you need to compare it with:
code:
var lastChar = Message.charAt(--Message.length);
if (lastChar == '?' || lastChar == '!' || lastChar == ':' || lastChar == '.' lastChar == ';' || lastChar == ',') {
Since you compare that same last character again and again with another character, you can turn this all around and check if that last character can be found into the string "?!:.;,". If so, you have a match if not you don't have a match. Use indexOf for this:
code:
if ("?!:.;,".indexOf(Message.charAt(--Message.length)) != -1) {

So now
code:
if (Message.substr((Message.length)-('?'.length)) == '?' || Message.substr((Message.length)-('!'.length)) == '!' || Message.substr((Message.length)-(':'.length)) == ':' || Message.substr((Message.length)-('.'.length)) == '.' || Message.substr((Message.length)-(';'.length)) == ';' || Message.substr((Message.length)-(','.length)) == ',') {
is reduced to:
code:
if ("?!:.;,".indexOf(Message.charAt(--Message.length)) != -1) {
And if you know regular expressions this can be simplified even more....:
code:
if (/[?!:.;,]$/.test(Message)) {



;)


Other stuff:
- remove that "Message = null" line. It is not needed. And luckally it is not executed either as that will otherwise produce an error. See this post for more info (and of course the Plus! Scripting Documentation).

- the case where (caps=="on" && dot=="on") doesn't check for already existing dots, commas, question marks, etc

Suggestions:
- Instead of having 4 IF THEN ELSE structures, split them up and examine exactly what each function does with the sentence in what case. You'll find that you will only need 2 IF THEN ELSE structures since you will only actually do something when a setting is on, not when it is off. You also do not need the ELSE case at all.

Result:
highlight to see it
code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
        var firstChar = Message.charAt(0);
        var restOfMessage = Message.substr(1);
        if (caps == "on") firstChar = firstChar.toUpperCase();
        if (dot == "on" && /[?!:.;,]$/.test(Message) == false) restOfMessage += ".";
        return firstChar + restOfMessage;
}


Bugs still to fix:
- You need to check if the message is not a command (messages beginning with "/" or even "!").
- Check individual lines (you could do this by splitting your message up into an array using the method split with delimiter "\n")
- If you define an ActiveX object, make sure it is always defined. Your code contains several occasion where you use an ActiveX object (WSH), but which isn't defined since you have placed it inside an IF THEN ELSE structure (see OnEvent_MenuClicked function).


More things you can make better:
code:
  if(MenuId=="caps"){
(...)
  if(MenuId=="dots"){
(...)
  if(MenuId=="about"){
(...)
  if(MenuId=="config"){
(...)
For something like this you better use the switch statement.

code:
if(caps=="on") {
      caps="off";
      WSH.RegWrite(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\" + "caps",caps);
}
else if(caps=="off") {
      caps="on";
      WSH.RegWrite(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\" + "caps",caps);
}
Put the same common lines outside the IF THEN ELSE structure. Then you'll also see that you can reduce the IF THEN ELSE structure to only 1 line using the conditional (ternary) operator. eg: to switch between two states:
myvar = (myvar == "1") ? "2" : "1"

But instead of using strings to indicate the states of the options, use booleans. They are way easier to work with and will reduce the code even further. eg: to switch between two states:
myvar = !myvar

Using booleans will extremely shorten all your code if you use it wisely.
RE: [Release] Capitals and full stops(Updated!)V1.1 by Jimbo on 10-21-2006 at 01:35 PM

Ok thanks for all the help cookie, will try to use booleans and all them things you mentioned in the next update(and maybe som more scripts from me!)


RE: [Release] Capitals and full stops(Updated!)V1.1 by MoonGoose on 10-21-2006 at 07:08 PM

nice work, but sometimes I don't get a capital in the beginning. It is turned on!!!


RE: [Release] Capitals and full stops(Updated!)V1.1 by Jimbo on 10-22-2006 at 10:07 AM

erm, try replacing the first function with this:

code:

function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
var firstChar = Message.charAt(0);
var restOfMessage = Message.substr(1);
if (caps == "on") firstChar = firstChar.toUpperCase();
if (dot == "on" && /[?!:.;,]$/.test(Message) == false) restOfMessage += ".";
return firstChar + restOfMessage;
}