What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Command Parsing Help

Command Parsing Help
Author: Message:
Stigmata
Veteran Member
*****



Posts: 3520
Reputation: 45
20 / Other / Flag
Joined: Jul 2003
O.P. Command Parsing Help
Now i wrote a quick command parsing bit for my script..

only thing is, the switch/case will not pick it up the string..

quote:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    var CMD = Message.split(" ", 1);
    Debug.Trace(CMD);
    if(MessageKind == 1){
        switch(CMD){
            case "!date" : ChatWnd.SendMessage("The date is: (!D)"); break;
            case "!time" : ChatWnd.SendMessage("The time is: (!T)"); break;
        }           
    }
}


the debug shows that the correct (splitted) string was used.

quote:
Function called: OnEvent_ChatWndReceiveMessage
!date


any ideas/help?
06-27-2006 09:01 PM
Profile PM Web Find Quote Report
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
RE: Command Parsing Help
Here's a good function that has always worked for me:

EDIT: put the function in and then use:
code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
     return parseCommands(Message,ChatWnd);
}

code:
function parseCommands(sMessage,ChatWnd){
      if (sMessage.charAt(0) == '/'){
            if(sMessage.charAt(1) == '/'){
                  return sMessage;
            } else {
                  var firstSpace = sMessage.search(' ');
                        if(firstSpace == -1){
                              var command = sMessage.toLowerCase().substr(1);
                              var params = '';
                        } else {
                              var command = sMessage.toLowerCase().substr(1, firstSpace-1);
                              var params = sMessage.toLowerCase().substr(firstSpace+1);
                        }
                              switch(command) {
                                    case 'whatever':
                                          //Do whatever here, but leave the next two lines. Add them to each case. They're important =)
                                          sMessage = '';
                                          break;
                                    }
                              }
            return sMessage;
      }
}

This post was edited on 06-27-2006 at 09:13 PM by deAd.
06-27-2006 09:09 PM
Profile PM Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: Command Parsing Help
quote:
Originally posted by Stigmata
code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    var CMD = Message.split(" ", 1);
    Debug.Trace(CMD[0]);
    if(MessageKind == 1){
        switch(CMD[0]){
            case "!date" : ChatWnd.SendMessage("The date is: (!D)"); break;
            case "!time" : ChatWnd.SendMessage("The time is: (!T)"); break;
        }           
    }
}


the debug shows that the correct (splitted) string was used.


The split function returns an Array!! Try the code above.
06-27-2006 09:14 PM
Profile E-Mail PM Find Quote Report
Stigmata
Veteran Member
*****



Posts: 3520
Reputation: 45
20 / Other / Flag
Joined: Jul 2003
O.P. RE: Command Parsing Help
quote:
Originally posted by J-Thread
The split function returns an Array!! Try the code above.

Bah yeah you're right... good point :P

fixed, updated and now it works fine :)

quote:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    if(MessageKind == 1){
        var CMD = Message.split(" ", 1).toString();
        switch(CMD.toLowerCase()){
            case "!date" : ChatWnd.SendMessage("The date is: (!D)"); break;
            case "!time" : ChatWnd.SendMessage("The time is: (!T)"); break;
        }           
    }
}



This post was edited on 06-27-2006 at 09:28 PM by Stigmata.
06-27-2006 09:25 PM
Profile PM Web 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