What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Need Help with my First Script

Pages: (2): « First « 1 [ 2 ] Last »
Need Help with my First Script
Author: Message:
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
RE: Need Help with my First Script
quote:
Originally posted by SamV522
Ok. So I've tried quite a few different things with sending a response, but it crashes whenever I try and send a message...
What am I doing wrong?
code:
function OnEvent_ChatWndSendMessage(ChatWnd,Origin, Message, MessageKind){
    if (Message.substr(0,6).toLowerCase() == "/AwayI"){
        var param = Message.substr(7);
        switch(param){
            case "enable":
                AI.State = true;
                break;
            case "disable":
                AI.State = false;
                break;
            case "commands":
                alert("Enable\nDisable\nCommands");
                break;
            /*default:
                alert("Invalid Command! Type \"/AwayI Commands\" to see a list of valid commands");
                break;
                */
        }
    }
}



Unless alert is your own custom function, it will fail. MP!L doesn't have an alert function. You can call a msgbox by using the relevant Win32 APIs or you can use Debug.Print to see it in the debug area. It shouldn't crash though, unless you just mean theres an error...

EDIT: Too slow, had to read other tabs first ¬_¬

This post was edited on 11-24-2009 at 06:25 PM by Spunky.
<Eljay> "Problems encountered: shit blew up" :zippy:
11-24-2009 06:25 PM
Profile PM Find Quote Report
SamV522
New Member
*


Posts: 10
Joined: Nov 2009
O.P. RE: Need Help with my First Script
No, msn just plain crashes... I'll post my current source.
http://msnplus.pastebin.com/mab45fd3
11-24-2009 06:32 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Need Help with my First Script
quote:
Originally posted by Spunky
Debug.Print
It is Debug.Trace not Debug.Print...

At what point does it crash? What message or command are you sending and it crashes?

This post was edited on 11-24-2009 at 07:08 PM by matty.
11-24-2009 06:53 PM
Profile E-Mail PM Find Quote Report
SamV522
New Member
*


Posts: 10
Joined: Nov 2009
O.P. RE: Need Help with my First Script
It crashes whenever I send any message
And on a side note: The AwayI command doesn't work.
I added this to ScriptInfo.xml in the right place and all but whenever I try and use it it says the command is not recognised.
code:
<ScriptCommands>
    <Command>
        <Name>AwayI</Name>
        <Description>Execute an AwayI command</Description>
        <Parameters>&lt;Command&gt;</Parameters>
    </Command>
</ScriptCommands>

11-24-2009 07:16 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Need Help with my First Script
Post all of your code here. use the [code=js][/code] and [code=xml][/code] tags to make it more readable.

Also you need to return ''; in the OnEvent_ChatWndSendMessage() when you are sending a custom command. Otherwise Plus! tries to parse the command and if it doesn't match one of the Plus! commands it errors out.
11-24-2009 07:19 PM
Profile E-Mail PM Find Quote Report
SamV522
New Member
*


Posts: 10
Joined: Nov 2009
O.P. RE: Need Help with my First Script
AwayI.js
Javascript code:
// Name: AwayI.js
// Author: SamV522
// Purpose: A.I. to respond to any messages while you're away.
 
var AI = {};
AI.Name = "Sophie";
AI.UnkownResponse = "I do not know how to respond to that, sorry.";
AI.Status = true;
AI.Responses = {};
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
 
function verify(){
    if (xmlDoc.readyState != 4){
        return false;
    }
}
 
function loadXML(xmlFile)
{
    xmlDoc.async="false";
    xmlDoc.onreadystatechange=verify;
    xmlDoc.load(xmlFile);
    xmlObj=xmlDoc.documentElement;
}
 
function OnEvent_SigninReady()
{
    if( AI.Status){
        loadXML("coms.xml");
        var In = "";
        var Out = "";
        for(i=0;i!=xmlObj.childNodes.length;i++){
            if(xmlObj.childNodes(i).childNodes(0).getAttribute("CaseSenseitive")=="false"){
                // The response IS case sensitive
                In = xmlObj.childNodes(i).childNodes(0).text;
                In = In.split(",");
                Out = xmlObj.childNodes(i).childNodes(1).text;
                Out = Out.split(",");
                for(i2=0;i2!=In.length;i2++){
                    AI.Responses[In[i2]].Resp = Out;
                    AI.Responses[In[i2]].CaseSens = false;
                }
            }else{
               
            }
        }
    }
}
 
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin, Message, MessageKind)
{
    var inMsg = Message;
    var resp = "Error!";
    for(i=0;i!=AI.Responses.length;i++){
        if(AI.Responses[Message]){
            if(AI.Responses[Message].CaseSens){
                inMsg = inMsg.toLowerCase();
            }else{
                inMsg = inMsg;
            }
           
            if(inMsg==AI.Responses[inMsg]){
                resp = AI.Responses[Message][Math.floor(Math.random()*Responses[Message].length)];
            }else{
                resp = AI.UnkownResponse;
            }
        }
        ChatWnd.SendMessage(resp);
    }
}
 
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
    if (Message.substr(0,6).toLowerCase() == "/AwayI"){
        var param = Message.substr(7);
        switch(param){
            case "enable":
                AI.State = true;
                return "";
            case "disable":
                AI.State = false;
                return "";
            case "commands":
                var WindowOptions=MsgPlus.CreateWnd("Commands.xml","CommandsWND");
                return "";
            /*default:
                alert("Invalid Command! Type \"/AwayI Commands\" to see a list of valid commands");
                break;
                */

        }
    }
}
 
function OnEvent_MenuClicked(sMenuId, nLocation, ChatWnd)
{
    switch(sMenuId){
        case "enableAI":
            AI.Status = true;
            break;
        case "disableAI":
            AI.Status = false;
            break;
        case "commandList":
            var WindowOptions=MsgPlus.CreateWnd("Interfaces.xml","commandsWND");
            break;
    }
}


ScriptInfo.xml:
XML code:
<?xml version="1.0"?>
<ScriptInfo xmlns="urn:msgplus:scripts" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="1.0">
<Information>
    <Name>AwayI MSN Bot</Name>
    <Description>An MSN Bot by SamV522</Description>
    <Version>1.0</Version>
</Information>
<ScriptMenu>
    <MenuEntry Id="enableAI">Enable</MenuEntry>
    <MenuEntry Id="disableAI">Disable</MenuEntry>
    <MenuEntry Id="commandList">Commands</MenuEntry>
 </ScriptMenu>
 
<ScriptCommands>
    <Command>
        <Name>AwayI</Name>
        <Description>Execute an AwayI command</Description>
        <Parameters>&lt;Command&gt;</Parameters>
    </Command>
</ScriptCommands>
</ScriptInfo>

11-24-2009 07:23 PM
Profile E-Mail PM Find Quote Report
SamV522
New Member
*


Posts: 10
Joined: Nov 2009
O.P. RE: Need Help with my First Script
Well... I fixed it  it was the if(AI.Responses[Message]) statement.
I changed it just to if(!AI.Responses[Message]){ return; }

This post was edited on 11-24-2009 at 08:02 PM by SamV522.
11-24-2009 07:55 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
RE: Need Help with my First Script
quote:
Originally posted by matty
quote:
Originally posted by Spunky
Debug.Print
It is Debug.Trace not Debug.Print...

At what point does it crash? What message or command are you sending and it crashes?

erm... =(
<Eljay> "Problems encountered: shit blew up" :zippy:
11-24-2009 08:00 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Need Help with my First Script
quote:
Originally posted by Spunky
quote:
Originally posted by matty
quote:
Originally posted by Spunky
Debug.Print
It is Debug.Trace not Debug.Print...

At what point does it crash? What message or command are you sending and it crashes?

erm... =(
Go back to VB coding :P
11-24-2009 08:29 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Need Help with my First Script
Your OnEvent_ChatWndSendMessage function is wrong. For starters the main if-then-statement will never return true since you change everything to lowercase and compare it with a mixed case string. Second, you must(!) return the original message if it isn't a command of your command.

corrected:
Javascript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
    if (Message.substr(0,6).toLowerCase() == "/awayi"){        var param = Message.substr(7);
        switch(param){
            case "enable":
                AI.State = true;
                return "";
            case "disable":
                AI.State = false;
                return "";
            case "commands":
                var WindowOptions=MsgPlus.CreateWnd("Commands.xml","CommandsWND");
                return "";
            /*default:
                alert("Invalid Command! Type \"/AwayI Commands\" to see a list of valid commands");
                break;
                */
        }
    } else {        return Message;    }
}


---------

In the OnEvent_ChatWndReceiveMessage function you first must check if you actually can send a message. See point 3 in my previous post.

And also, just as in OnEvent_ChatWndSendMessage, you must(!) return the original message if you're not going to change it.

This post was edited on 11-24-2009 at 08:47 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
11-24-2009 08:35 PM
Profile PM Find Quote Report
Pages: (2): « First « 1 [ 2 ] Last »
« 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