Multiple Function Call/callbacks - 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: Multiple Function Call/callbacks (/showthread.php?tid=79464)
Multiple Function Call/callbacks by ArkaneArkade on 11-29-2007 at 12:44 PM
Hey guys,
I need advice yet again. I have written a script which checks an html interface and outputs the information scraped to a contact. Or rather, thats my intention. I've spent 10 mins trying to write this, but it doesnt make sense even to me, so please excuse the random code.
code: function AzureusInfoFetch()
{
http = new ActiveXObject("Microsoft.XMLHTTP");
http.onreadystatechange=AzureusInfoRead();
http.open("GET", "http://" + "192.168.0.2" + ":" + "6885/index.tmpl", true, "StevieD", "leroux should edit his password out of scripts he posts on the forums");
http.send(null);
}
function AzureusInfoRead()
{
if ((http.readyState == 4) && (http.status == 200))
{
var Azureus = AzureusInfo(http.responseText);
Debug.Trace(Azureus);
}
http.close;
}
function AzureusInfo(text)
{
if (text.indexOf('<tr id="r'+n) > -1)
{
XBMCArtist = text.substring(text.indexOf('<tr id="r1"'), text.length);
XBMCArtist = XBMCArtist.substring(0, XBMCArtist.indexOf('</tr>')+5);
XBMCArtist=XBMCArtist.split("<td");
.....
}
Theres various formatting in this code, and it all works according to debug, but the basic point I need is for it to be called by a contact. I'm looking for the function AzureusInfoFetch() to be called when a contacts sends the message "!azureus", and then once all of the data is fetched and formatted through the other functions will send it back to the contact. I don't suppose anyone can suggest a way to do this, because I just dont seem to be able to get my head around it.
Cheers
[Sorry for the misleading topic name earlier. I got confused while writing and ending up changing what I needed help with. I wasnn't trying to trick people into viewing. Sorry]
RE: Multiple Function Call/callbacks by -dt- on 11-30-2007 at 12:30 AM
er just check for it on received message
code: function OnEvent_ChatWndReceiveMessage (wnd, origin, msg){
switch(msg){
case "!xxx" : wnd.SendMessage(AzureusInfoFetch()); break;
}
}
(the function name may be incorrect, since I'm unable to download the scripting docs here )
RE: Multiple Function Call/callbacks by markee on 11-30-2007 at 03:27 AM
quote: Originally posted by -dt-
er just check for it on received message
code: function OnEvent_ChatWndReceiveMessage (wnd, origin, msg){
switch(msg){
case "!xxx" : wnd.SendMessage(AzureusInfoFetch()); break;
}
}
(the function name may be incorrect, since I'm unable to download the scripting docs here )
That is very silly as the only way it will work (due to async) is to freeze messenger while it gets it
What you need to do is parse the chat window object through all of your functions as an extra parameter and then at the end of AzureusInfo() you can send it to that chat window using the SendMessage method of that chat window object you parsed through. I would edit the code to show you but I'm feel lazy
RE: Multiple Function Call/callbacks by -dt- on 11-30-2007 at 03:37 AM
quote: Originally posted by markee
quote: Originally posted by -dt-
er just check for it on received message
code: function OnEvent_ChatWndReceiveMessage (wnd, origin, msg){
switch(msg){
case "!xxx" : wnd.SendMessage(AzureusInfoFetch()); break;
}
}
(the function name may be incorrect, since I'm unable to download the scripting docs here )
That is very silly as the only way it will work (due to async) is to freeze messenger while it gets it
it was just a quickly written example, I assumed that all he wanted to know was how to have data sent back when someone says !xxx. ;o but it seems now that I misread his post, and he wanted to know how to send the message from the callback ;o
code:
function AzureusInfoFetch(wnd)
{
http = new ActiveXObject("Microsoft.XMLHTTP");
http.onreadystatechange=function(){
if ((http.readyState == 4) && (http.status == 200))
{
var Azureus = AzureusInfo(http.responseText);
wnd.SendMessage(Azureus);
}
http.close();
}
http.open("GET", "http://" + "192.168.0.2" + ":" + "6885/index.tmpl", true, "StevieD", "lolpassword");
http.send(null);
}
function AzureusInfo(text)
{
if (text.indexOf('<tr id="r'+n) > -1)
{
XBMCArtist = text.substring(text.indexOf('<tr id="r1"'), text.length);
XBMCArtist = XBMCArtist.substring(0, XBMCArtist.indexOf('</tr>')+5);
XBMCArtist=XBMCArtist.split("<td");
.....
}
function OnEvent_ChatWndReceiveMessage (wnd, origin, msg){
switch(msg){
case "!xxx" : AzureusInfoFetch(wnd); break;
}
}
that should work ;o
RE: Multiple Function Call/callbacks by ArkaneArkade on 11-30-2007 at 10:27 PM
OK, that worked brilliantly. Thanks a lot I should have thought of it, but I'm not sleeping and so tired I cant even spell my name right (seriously). Also, thanks to whoever removed the password from my post - I can't believe I did that.
Cheers as always guys
[Edited to remove the horrendous spelling]
On another thought, is there a way for me to return multiple replies from the same function, or would everything need to be done in multiple global vars.
eg.
function SendInfo(){
SetInfo();
Messenger.SetNick(returned info[1]);
Messenger.SetPSM(returned info[2]);
)
function SetInfo(){
info[1] = "Stefan Leroux";
info[2] = "Scripting God (LOL)";
}
I know the setnick/setpsm dont work, but its just for an example. Is there any way to do it?
Thanks
RE: Multiple Function Call/callbacks by Matti on 12-01-2007 at 09:15 AM
Sure, just make the function return an array!
code: function SendInfo() {
var arrayInfo = SetInfo();
Messenger.MyName = arrayInfo[0];
Messenger.MyPersonalMessage = arrayInfo[1];
}
function SetInfo() {
var returns = new Array();
returns[0] = "Stefan Leroux";
returns[1] = "Scripting God (LOL)";
return returns;
}
RE: Multiple Function Call/callbacks by ArkaneArkade on 12-01-2007 at 09:24 AM
Brilliant. I'll get right on that. Thank you Mattike.
|