Command Parsing Help - 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: Command Parsing Help (/showthread.php?tid=61811)
Command Parsing Help by Stigmata on 06-27-2006 at 09:01 PM
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?
RE: Command Parsing Help by deAd on 06-27-2006 at 09:09 PM
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;
}
}
RE: Command Parsing Help by J-Thread on 06-27-2006 at 09:14 PM
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.
RE: Command Parsing Help by Stigmata on 06-27-2006 at 09:25 PM
quote: Originally posted by J-Thread
The split function returns an Array!! Try the code above.
Bah yeah you're right... good point
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;
}
}
}
|