Shoutbox

Problem 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: Problem with my script. (/showthread.php?tid=64799)

Problem with my script. by TheTomb on 08-11-2006 at 07:10 PM

I'm making my first script which is called Interpreter which steals your Contacts name. I don't know if it's right or not but it comes up saying

"/interpretate is not recognised as a command"

Heres my code

code:
function OnEvent_Initialize(MessengerStart)
{
}

function OnEvent_Uninitialize(MessengerExit)
{
}

function OnGetScriptCommands(){
var commands = '<ScriptCommands>';
commands+='<Command>';
commands+='<Name>interpretate</Name>';
commands+='<Description>Interpretate your contact by stealing their name!</Description>';
commands+='<Parameters/>';
commands+='</Command>';
commands+='</ScriptCommands>';
return commands;
}

function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
  if(Message == "/interpretate")
  {
  Messenger.MyName = Contact.Name
  MsgPlus.DisplayToast("Success!", "You have the same name as your contact!");
  return '';
  }
}


RE: Problem with my script. by matty on 08-11-2006 at 07:12 PM

quote:
Originally posted by TheTomb
Messenger.MyName = Contact.Name
Because Contact.Name doesn't exist anywhere. You need to iterate through the ChatWnd.Contacts object to get a Contact object which you can get the contacts name from.
RE: Problem with my script. by TheTomb on 08-11-2006 at 07:14 PM

and how am I supposed to do that?


RE: Problem with my script. by Felu on 08-11-2006 at 07:26 PM

code:
function OnGetScriptCommands(){
var commands = '<ScriptCommands>';
commands+='<Command>';
commands+='<Name>interpretate</Name>';
commands+='<Description>Interpretate your contact by stealing their name!</Description>';
commands+='<Parameters/>';
commands+='</Command>';
commands+='</ScriptCommands>';
return commands;
}

function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
  if(Message.substr(0,13) == "/interpretate")
  {
  var Contacts = ChatWnd.Contacts;
  var e = new Enumerator(Contacts); for(; !e.atEnd(); e.moveNext())
  var Blah = e.item()
  Messenger.MyName = Blah.Name;
  MsgPlus.DisplayToast("Success!", "You have the same name as your contact!");
  return '';
  }
}

Use that code ;)
RE: Problem with my script. by TheTomb on 08-12-2006 at 08:15 AM

I still get

'The command you entered was not recognised'


RE: Problem with my script. by vikke on 08-12-2006 at 08:17 AM

Try

code:
var commands = new String();
commands+='<ScriptCommands>';
commands+='<Command>';
commands+='<Name>interpretate</Name>';
commands+='<Description>Interpretate your contact by stealing their name!</Description>';
commands+='<Parameters/>';
commands+='</Command>';
commands+='</ScriptCommands>';
return commands;

RE: Problem with my script. by TheTomb on 08-12-2006 at 08:20 AM

Nope, now it doesn't appear in the

/ list


RE: Problem with my script. by vikke on 08-12-2006 at 08:23 AM

Hmm ok, strange.
Well.. return "; should be return "";


RE: Problem with my script. by Eljay on 08-12-2006 at 08:26 AM

code:
function OnGetScriptCommands(){
  var commands = '<ScriptCommands>';
  commands+='<Command>';
  commands+='<Name>interpretate</Name>';
  commands+='<Description>Interpretate your contact by stealing their name!</Description>';
  commands+='<Parameters/>';
  commands+='</Command>';
  commands+='</ScriptCommands>';
  return commands;
}

function OnEvent_ChatWndSendMessage(ChatWnd, Message){
  if(Message.substr(0,13) == "/interpretate"){
    for(e = new Enumerator(ChatWnd.Contacts); !e.atEnd(); e.moveNext()){
      var Contact = e.item()
      Messenger.MyName = Contact.Name;
      MsgPlus.DisplayToast("Success!", "You have the same name as your contact!");
      return '';
    }
  }
}

RE: Problem with my script. by Felu on 08-12-2006 at 08:34 AM

quote:
Originally posted by TheTomb
I still get

'The command you entered was not recognised'
Hmm... The code i gave works perfectly fine. Can you please post the code you are using?
quote:
Originally posted by vikke
Try
code:
var commands = new String();
commands+='<ScriptCommands>';
commands+='<Command>';
commands+='<Name>interpretate</Name>';
commands+='<Description>Interpretate your contact by stealing their name!</Description>';
commands+='<Parameters>';
commands+='</Parameters>';
commands+='</Command>';
return commands;

That wont work [Image: msn_sad.gif].

Edit
   
quote:
Originally posted by -!Felu!-
code:
    function OnGetScriptCommands(){
    var commands = '<ScriptCommands>';
    commands+='';
    commands+='interpretate';
    commands+='Interpretate your contact by stealing their name!';
    commands+='';
    commands+='';
    commands+='';
    return commands;
    }

    function OnEvent_ChatWndSendMessage(ChatWnd, Message)
    {
    if(Message.substr(0,13) == "/interpretate")
    {
    var Contacts = ChatWnd.Contacts;
    var e = new Enumerator(Contacts); for(; !e.atEnd(); e.moveNext())
    var Blah = e.item()
    Messenger.MyName = Blah.Name;
    MsgPlus.DisplayToast("Success!", "You have the same name as your contact!");
    return '';
    }
    }

    Use that code


   
quote:
Originally posted by Eljay
code:
function OnGetScriptCommands(){
    var commands = '<ScriptCommands>';
    commands+='';
    commands+='interpretate';
    commands+='Interpretate your contact by stealing their name!';
    commands+='';
    commands+='';
    commands+='';
    return commands;
    }

    function OnEvent_ChatWndSendMessage(ChatWnd, Message){
    if(Message.substr(0,13) == "/interpretate"){
    for(e = new Enumerator(ChatWnd.Contacts); !e.atEnd(); e.moveNext()){
    var Contact = e.item()
    Messenger.MyName = Contact.Name;
    MsgPlus.DisplayToast("Success!", "You have the same name as your contact!");
    return '';
    }
    }
    }



Whats the difference Eljay? Just Blah is Contact and ChatWnd.Contacts is defined as Contacts in my code and your code directly uses ChatWnd.Contacts :undecided:.
RE: Problem with my script. by vikke on 08-12-2006 at 08:38 AM

But there's one syntax error, if you look,

code:
return ";
should be
code:
return "";

RE: Problem with my script. by TheTomb on 08-12-2006 at 08:39 AM

code:
function OnEvent_Initialize(MessengerStart)
{
}

function OnEvent_Uninitialize(MessengerExit)
{
}

function OnGetScriptCommands(){
var commands = '<ScriptCommands>';
commands+='<Command>';
commands+='<Name>interpretate</Name>';
commands+='<Description>Interpretate your contact by stealing their name!</Description>';
commands+='<Parameters/>';
commands+='</Command>';
commands+='</ScriptCommands>';
return commands;
}

function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
  if(Message.substr(0,13) == "/interpretate")
  {
  var Contacts = ChatWnd.Contacts;
  var e = new Enumerator(Contacts); for(; !e.atEnd(); e.moveNext())
  var Blah = e.item()
  Messenger.MyName = Blah.Name;
  MsgPlus.DisplayToast("Success!", "You have the same name as your contact!");
  return '';
  }
}

That is my Interpreter.js

code:
<?xml version="1.0" encoding="UTF-16"?>
<ScriptInfo xmlns="urn:msgplus:scripts" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Information>
        <Name>Interpreter</Name>
        <Description>Steal the name of your contact!</Description>
        <AboutUrl>http://thetomb.co.uk</AboutUrl>
</Information>
</ScriptInfo>

Thats my ScriptInfo.xml

EDIT: Fixed, the Script wasnt activated :D Sorry for wasting your time.

Felu that works fine :)
RE: Problem with my script. by Felu on 08-12-2006 at 08:42 AM

TheTomb that Interpreter.js works perfectly fine *-). Dont know why is it that you cant use that code?


RE: Problem with my script. by Eljay on 08-12-2006 at 08:50 AM

quote:
Originally posted by -!Felu!-
Whats the difference Eljay? Just Blah is Contact

When using for() without opening and closing braces, only the first statement is executed (in this case, "var Blah = e.item()"). for multiple statements in a statement/loop you need to enclose the code in {} for it to be executed (otherwise where would the script know when to stop?)

or maybe thats just javascript not jscript, but i doubt it. its neater anyway :P
RE: Problem with my script. by TheTomb on 08-12-2006 at 09:05 AM

OK that problem is fixed but i've tried to add another command which changed your name back, heres my code.

code:
var OldName = "";

function OnEvent_Initialize(MessengerStart)
{
}

function OnEvent_Uninitialize(MessengerExit)
{
}

function OnGetScriptCommands(){
var commands = '<ScriptCommands>';
commands+='<Command>';
commands+='<Name>intstealname</Name>';
commands+='<Description>Steal your contacts name!</Description>';
commands+='<Parameters/>';
commands+='</Command>';
commands+='<Command>';
commands+='<Name>intoldname</Name>';
commands+='<Description>Change your name back to the previous name!</Description>';
commands+='<Parameters/>';
commands+='</Command>';
commands+='</ScriptCommands>';
return commands;
}

function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
  if(Message.substr(0,13) == "/intstealname")
  {
  OldName = Messenger.MyName;
  var Contacts = ChatWnd.Contacts;
  var e = new Enumerator(Contacts); for(; !e.atEnd(); e.moveNext())
  var Blah = e.item()
  Messenger.MyName = Blah.Name;
  MsgPlus.DisplayToast("Interpreter 1.0", "You are now interpretating your contact!");
  return '';
  }
  if(Message.substr(0,9) == "/intoldname")
  {
  if(OldName = ""){
  MsgPlus.DisplayToast("Interpreter 1.0", "You dont have an old name!");
  }else{
  Messenger.MyName = OldName;
  MsgPlus.DisplayToast("Interpreter 1.0", "Your name is back to normal!");
  return '';
  }
  }
}

It comes up with the same error and the script is enabled.
RE: Problem with my script. by Shondoit on 08-12-2006 at 01:44 PM

The last 'return "" ' should be outside the brackets, so it works for both when OldName has, and hasn't got a value
You forgot the brackets { } again, this should work:

code:
var OldName = "";

function OnGetScriptCommands(){
   var commands = '<ScriptCommands>';
   commands+='<Command>';
   commands+='<Name>intstealname</Name>';
   commands+='<Description>Steal your contacts name!</Description>';
   commands+='<Parameters/>';
   commands+='</Command>';
   commands+='<Command>';
   commands+='<Name>intoldname</Name>';
   commands+='<Description>Change your name back to the previous name!</Description>';
   commands+='<Parameters/>';
   commands+='</Command>';
   commands+='</ScriptCommands>';
   return commands;
}

function OnEvent_ChatWndSendMessage(ChatWnd, Message){
   if(Message.substr(0,13) == "/intstealname"){
      OldName = Messenger.MyName;
      var Contacts = ChatWnd.Contacts;
      var e = new Enumerator(Contacts);
      for(; !e.atEnd(); e.moveNext()){
         var Contact = e.item()
         Messenger.MyName = Contact.Name;
         MsgPlus.DisplayToast("Interpreter 1.0", "You are now interpretating your contact!");
         return '';
      }
   }else if(Message.substr(0,9) == "/intoldname"){
      if(OldName = ""){
         MsgPlus.DisplayToast("Interpreter 1.0", "You dont have an old name!");
      }else{
         Messenger.MyName = OldName;
         MsgPlus.DisplayToast("Interpreter 1.0", "Your name is back to normal!");
      }
      return '';
   }
}

RE: Problem with my script. by Felu on 08-12-2006 at 02:16 PM

Here's the fixed code. See BOLD letters for the change made.

code:
var OldName;

function OnGetScriptCommands(){
    var commands = '<ScriptCommands>';
    commands+='<Command>';
    commands+='<Name>intstealname</Name>';
    commands+='<Description>Steal your contacts name!</Description>';
    commands+='<Parameters/>';
    commands+='</Command>';
    commands+='<Command>';
    commands+='<Name>intoldname</Name>';
    commands+='<Description>Change your name back to the previous name!</Description>';
    commands+='<Parameters/>';
    commands+='</Command>';
    commands+='</ScriptCommands>';
    return commands;
    }

function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
      if(Message.substr(0,13) == "/intstealname")
      {
      OldName = Messenger.MyName;
      var Contacts = ChatWnd.Contacts;
      var e = new Enumerator(Contacts); for(; !e.atEnd(); e.moveNext())
      var Blah = e.item()
      Messenger.MyName = Blah.Name;
      MsgPlus.DisplayToast("Interpreter 1.0", "You are now interpretating your contact!");
      return '';
      }
      if(Message.substr(0,11) == "/intoldname")
      {
      if(OldName == null){
      MsgPlus.DisplayToast("Interpreter 1.0", "You dont have an old name!");
      }else{
      Messenger.MyName = OldName;
      MsgPlus.DisplayToast("Interpreter 1.0", "Your name is back to normal!");
      }
      return '';

      }
    }