Need Help with my First Script |
Author: |
Message: |
Spunky
Former Super Mod
Posts: 3658 Reputation: 61
36 / /
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"
|
|
11-24-2009 06:25 PM |
|
|
SamV522
New Member
Posts: 10
Joined: Nov 2009
|
|
11-24-2009 06:32 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 |
|
|
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><Command></Parameters>
</Command>
</ScriptCommands>
|
|
11-24-2009 07:16 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 |
|
|
SamV522
New Member
Posts: 10
Joined: Nov 2009
|
O.P. RE: Need Help with my First Script
AwayI.js
js 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><Command></Parameters>
</Command>
</ScriptCommands>
</ScriptInfo>
|
|
11-24-2009 07:23 PM |
|
|
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 |
|
|
Spunky
Former Super Mod
Posts: 3658 Reputation: 61
36 / /
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"
|
|
11-24-2009 08:00 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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
|
|
11-24-2009 08:29 PM |
|
|
CookieRevised
Elite Member
Posts: 15517 Reputation: 173
– / /
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: js 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 |
|
|
Pages: (2):
« First
«
1
[ 2 ]
Last »
|
|