Shoutbox

why won't this work? - 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: why won't this work? (/showthread.php?tid=67472)

why won't this work? by Jimbo on 10-19-2006 at 04:22 PM

why won't this work?

code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if (Message.substr(0, 6) == "bye"){
return'/signout'
}
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if (Message.substr(0, 6) == "away"){
return'/away'
}
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if (Message.substr(0, 6) == "back"){
return'online'


RE: why won't this work? by markee on 10-19-2006 at 04:25 PM

Its because you cant have more than one functioned named the one thing unless they are local functions


RE: why won't this work? by Felu on 10-19-2006 at 04:25 PM

You can use OnEvent_ChatWndSendMessage only once... so

code:

function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if (Message.substr(0, 3)== "bye"){
return'/signout'
}
if (Message.substr(0, 4) == "away"){
return'/away'
}
if (Message.substr(0, 4) == "back"){
return'online'
}
}
should work.


Also message.substr was used in the wrong way
RE: why won't this work? by Shondoit on 10-19-2006 at 04:26 PM

It would work but you can only have one function with a specified name, so you have to put all options together, like this:

code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
   if (Message.substr(0, 6) == "bye"){
      return'/signout'
   }else if (Message.substr(0, 6) == "away"){
      return'/away'
   } else if (Message.substr(0, 6) == "back"){
      return '/online'
   }
}

Edit: Beaten by Felu
RE: why won't this work? by Jimbo on 10-19-2006 at 04:27 PM

lol, thanks everyone. they were very fast replys


RE: why won't this work? by Felu on 10-19-2006 at 04:28 PM

quote:
Originally posted by JimboDude
lol, thanks everyone. they were very fast replys
Please see my edit. You were using Message.substr the wrong way [Image: msn_tongue.gif].
RE: why won't this work? by Jimbo on 10-19-2006 at 04:31 PM

quote:
Originally posted by -!Felu!-
quote:
Originally posted by JimboDude
lol, thanks everyone. they were very fast replys
Please see my edit. You were using Message.substr the wrong way [Image: msn_tongue.gif].
ok, thanks

RE: why won't this work? by Ezra on 10-19-2006 at 04:43 PM

Also why return a command if you can do it directly with the script?

code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
  if (Message.match(/^bye$/i) != null)
  {
    Messenger.Signout();
    return "";
  }
  else if (Message.match(/^away$/i) != null)
  {
    Messenger.MyStatus = 7; //Set status to Away;
    return "";
  }
  else if (Message.match(/^back$/i) != null)
  {
    if (ChatWnd.EditChangeAllowed)
    {
      return "Online";
    }
    else
    {
      Debug.Trace("Could not return a value");
      return "";
    }
  }
  else
  {
    if (ChatWnd.EditChangeAllowed)
    {
      return Message;
    }
    else
    {
      Debug.Trace("Could not return a value");
      return "";
    }
  }
}

Uses the direct functions and uses regex to compare the Message.

EDIT:

AND it returns the complete Message if anything else was said ;)
RE: why won't this work? by Jimbo on 10-19-2006 at 04:44 PM

quote:
Originally posted by Ezra
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if (Message.substr(0, 3)== "bye"){
return'/signout'
}
if (Message.substr(0, 4) == "away"){
return'/away'
}
if (Message.substr(0, 4) == "back"){
return'online'
}
}
ok, but wouldn't this code still work by !felu!
code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if (Message.substr(0, 3)== "bye"){
return'/signout'
}
if (Message.substr(0, 4) == "away"){
return'/away'
}
if (Message.substr(0, 4) == "back"){
return'online'
}
}