Shoutbox

[Solved] What is wrong with my script? - 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: [Solved] What is wrong with my script? (/showthread.php?tid=63157)

[Solved] What is wrong with my script? by markee on 07-13-2006 at 08:36 AM

Can someone please tell me what's wrong with this script.  It is meant to make your text a gradient for the people you select.  It also uses the commands /colour1 /colour2 for the colours of the gradient and /contact to be able to send the gradient to that contact and /contactdelete to remove the contaact from being able to receive the gradient text.  It is also not meant to work when you are writing a command but work when you have "//" at the begining of your message.  Thanks in advance.

code:
function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
  var ChatWndContacts = ChatWnd.Contacts;
  if(ChatWndContacts.Count == 1)
  {
    var e = new Enumerator(ChatWndContacts);
    var Contact = e.item();
    var WSH = new ActiveXObject('WScript.Shell');
    try
    {
      WSH.RegRead(MsgPlus.ScriptRegPath + Contact.Email);
      Debug.Trace(MsgPlus.ScriptRegPath + "numberofpies exists.");
      var WSH = new ActiveXObject('WScript.Shell');
      colour1no = WSH.RegRead(MsgPlus.ScriptRegPath + "colour1");
      var WSH = new ActiveXObject('WScript.Shell');
      colour2no = WSH.RegRead(MsgPlus.ScriptRegPath + "colour2");
      if (Message.charAt(0) == '/')
      {
        if(Message.charAt(1) == '/')
        {
          ChatWnd.SendMessage("[c" + colour1no + "]" + Message + "[/c=" + colour2no + "]");
        }
        return Message;
      }
      ChatWnd.SendMessage("[c" + colour1no + "]" + Message + "[/c=" + colour2no + "]");
    }
    catch (e)
    {
    Debug.Trace(MsgPlus.ScriptRegPath + "numberofpies doesnt exists.");
    ChatWnd.SendMessage(Message)
    }
  }
  Debug.Trace(MsgPlus.ScriptRegPath + "number of contacts more than one");
}
function OnEvent_ChatWndSendMessage(ChatWnd, sMessage) {

    if(sMessage.charAt(0) == "/"){
        return parseCommands(sMessage,ChatWnd);
    }
}
function parseCommands(sMessage,ChatWnd){
  var ChatWndContacts = ChatWnd.Contacts;
  if(ChatWndContacts.Count == 1)
  {
    var e = new Enumerator(ChatWndContacts);
    var Contact = e.item();
    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.substr(firstSpace+1);
            }
            if(params != "") { Debug.Trace("The command \"" + command + "\" with the parameters \"" + params + "\" has been parsed."); }
            else { Debug.Trace("The command \"" + command + "\" has been parsed."); }
            switch(command) {
                case 'colour1':
                    var colour1no = params
                    {
                      new ActiveXObject('WScript.Shell').RegWrite(MsgPlus.ScriptRegPath + "colour1",colour1no);
                    }
                    sMessage = '';
                    break;
                case 'colour2':
                    var colour2no = params
                    {
                      new ActiveXObject('WScript.Shell').RegWrite(MsgPlus.ScriptRegPath + "colour2",colour2no);
                    }
                    sMessage = '';
                    break;
                case 'contact':
                    var Message = params
                    {
                      new ActiveXObject('WScript.Shell').RegWrite(MsgPlus.ScriptRegPath + Contact.Email,Message);
                    }
                    sMessage = '';
                    break;
                case 'contactdelete':
                    {
                      new ActiveXObject('WScript.Shell').RegDelete(MsgPlus.ScriptRegPath + Contact.Email);
                    }
                    sMessage = '';
                    break;
                default:
            }
        }
    }
    return sMessage;
}
}
function OnGetScriptCommands()
{
    var commands = '<ScriptCommands>';
        commands+='<Command>';
            commands+='<Name>colour1</Name>';
            commands+='<Description>'+"First colour for gradient"+'</Description>';
            commands+='<Parameters>Message</Parameters>';
        commands+='</Command>';
        commands+='<Command>';
            commands+='<Name>colour2</Name>';
            commands+='<Description>'+"Second colour for gradient"+'</Description>';
            commands+='<Parameters>Message</Parameters>';
        commands+='</Command>';
        commands+='<Command>';
            commands+='<Name>contact</Name>';
            commands+='<Description>'+"Add contact to receive gradient message list"+'</Description>';
            commands+='<Parameters>Message</Parameters>';
        commands+='</Command>';
        commands+='<Command>';
            commands+='<Name>contactdelete</Name>';
            commands+='<Description>'+"Remove contact from receive gradient list"+'</Description>';
            commands+='<Parameters>Message</Parameters>';
        commands+='</Command>';
    commands+='</ScriptCommands>';
    return commands;
}


Edit: you must also set the colours and a contact before being able to use the script properly
RE: [Help] What is wrong with my script? by -dt- on 07-13-2006 at 08:52 AM

quote:
Originally posted by shoutbox

<-dt-> :-/ you know you dont have to redeclare "WScript.Shell" each time
<-dt-> just assign it to a variable and use it :sad:
<-dt-> also wtf at the OnGetScriptCommands xml ... :/ why are you adding two strings together....just use one
<-dt-> also ChatWnd.SendMessage("[c" + colour1no + "]" + Message + "[/c=" + colour2no + "]"); , the first one you're missing an =


also

code:
17          if (Message.charAt(0) == '/')
18          {
19            if(Message.charAt(1) == '/')


err? so they enter // for it to work?
RE: RE: [Help] What is wrong with my script? by markee on 07-13-2006 at 09:22 AM

quote:
Originally posted by -dt-
quote:
Originally posted by shoutbox

<-dt-> :-/ you know you dont have to redeclare "WScript.Shell" each time
<-dt-> just assign it to a variable and use it :sad:
<-dt-> also wtf at the OnGetScriptCommands xml ... :/ why are you adding two strings together....just use one
<-dt-> also ChatWnd.SendMessage("[c" + colour1no + "]" + Message + "[/c=" + colour2no + "]"); , the first one you're missing an =


also

code:
17          if (Message.charAt(0) == '/')
18          {
19            if(Message.charAt(1) == '/')


err? so they enter // for it to work?


Ok, well I fixed everything you said apart from changing the script commands to an .xml file, I just kept them in the script like I had before.  I also added "else" in a couple of places that I realised I was missing from you pointing it out.  I'm still having troubles with the sending the message part, I made sure that it saved to the regestry and I added the Debug.Trace 's before and none of them seem to be triggering either.

Here's what the code looks like now

code:
function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
  var ChatWndContacts = ChatWnd.Contacts;
  if(ChatWndContacts.Count == 1)
  {
    var e = new Enumerator(ChatWndContacts);
    var Contact = e.item();
    var WSH = new ActiveXObject('WScript.Shell');
    try
    {
      WSH.RegRead(MsgPlus.ScriptRegPath + Contact.Email);
      Debug.Trace(MsgPlus.ScriptRegPath + "numberofpies exists.");
      colour1no = WSH.RegRead(MsgPlus.ScriptRegPath + "colour1");
      colour2no = WSH.RegRead(MsgPlus.ScriptRegPath + "colour2");
      if (Message.charAt(0) == '/')
      {
        if(Message.charAt(1) == '/')
        {
          ChatWnd.SendMessage("[c=" + colour1no + "]" + Message + "[/c=" + colour2no + "]");
        }
        else
        {
          return Message;
        }
      }
      else
      {
        ChatWnd.SendMessage("[c=" + colour1no + "]" + Message + "[/c=" + colour2no + "]");
      }
    }
    catch (e)
    {
    Debug.Trace(MsgPlus.ScriptRegPath + "numberofpies doesnt exists.");
    ChatWnd.SendMessage(Message)
    }
  }
  Debug.Trace(MsgPlus.ScriptRegPath + "number of contacts more than one");
}
function OnEvent_ChatWndSendMessage(ChatWnd, sMessage) {

    if(sMessage.charAt(0) == "/"){
        return parseCommands(sMessage,ChatWnd);
    }
}
function parseCommands(sMessage,ChatWnd){
  var ChatWndContacts = ChatWnd.Contacts;
  if(ChatWndContacts.Count == 1)
  {
    var e = new Enumerator(ChatWndContacts);
    var Contact = e.item();
    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.substr(firstSpace+1);
            }
            if(params != "") { Debug.Trace("The command \"" + command + "\" with the parameters \"" + params + "\" has been parsed."); }
            else { Debug.Trace("The command \"" + command + "\" has been parsed."); }
            switch(command) {
                case 'colour1':
                    var colour1no = params
                    {
                      new ActiveXObject('WScript.Shell').RegWrite(MsgPlus.ScriptRegPath + "colour1",colour1no);
                    }
                    sMessage = '';
                    break;
                case 'colour2':
                    var colour2no = params
                    {
                      new ActiveXObject('WScript.Shell').RegWrite(MsgPlus.ScriptRegPath + "colour2",colour2no);
                    }
                    sMessage = '';
                    break;
                case 'contact':
                    var Message = params
                    {
                      new ActiveXObject('WScript.Shell').RegWrite(MsgPlus.ScriptRegPath + Contact.Email,Message);
                    }
                    sMessage = '';
                    break;
                case 'contactdelete':
                    {
                      new ActiveXObject('WScript.Shell').RegDelete(MsgPlus.ScriptRegPath + Contact.Email);
                    }
                    sMessage = '';
                    break;
                default:
            }
        }
    }
    return sMessage;
}
}
function OnGetScriptCommands()
{
    var commands = '<ScriptCommands>';
        commands+='<Command>';
            commands+='<Name>colour1</Name>';
            commands+='<Description>'+"First colour for gradient"+'</Description>';
            commands+='<Parameters>Message</Parameters>';
        commands+='</Command>';
        commands+='<Command>';
            commands+='<Name>colour2</Name>';
            commands+='<Description>'+"Second colour for gradient"+'</Description>';
            commands+='<Parameters>Message</Parameters>';
        commands+='</Command>';
        commands+='<Command>';
            commands+='<Name>contact</Name>';
            commands+='<Description>'+"Add contact to receive gradient message list"+'</Description>';
            commands+='<Parameters>Message</Parameters>';
        commands+='</Command>';
        commands+='<Command>';
            commands+='<Name>contactdelete</Name>';
            commands+='<Description>'+"Remove contact from receive gradient list"+'</Description>';
            commands+='<Parameters>Message</Parameters>';
        commands+='</Command>';
    commands+='</ScriptCommands>';
    return commands;
}


I hope you can find what the problem is.
RE: [Help] What is wrong with my script? by markee on 07-14-2006 at 05:24 AM

Ok well I've worked out what I've done wrong. Thanks for the help anyway.