Shoutbox

[Help] Scripting Problem - 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: [Help] Scripting Problem (/showthread.php?tid=91457)

[Help] Scripting Problem by Shadowajohn on 07-13-2009 at 08:22 PM

Not sure if this should be in help & support or scripting..so i put in h&s.

A while ago i made a Xbox360 script (well edited from an old last.fm script with permission) which more or less allows you to post your Xbox Live gamerscore and status to MSN.
I've recently noticed the status function i added no longer works,

It used to output something like:

code:
360 - Shadowajohn: Playing Magic: The Gathering - Playing Campaign (Single Player). Life:16
Now it outputs:
code:
360 - Shadowajohn: Valid - Valid
I've not changed anything since it worked, yet it doesn't work anymore.
I have very limited knowledge in java or xml..and i've tried nearly everything i think it could be.

Here's the full code

code:
//////////////////
// Globals vars //
//////////////////
var GamerTag = '';
var WScript = new ActiveXObject('WScript.Shell');
var message = '';
var user = new Array();
var PC = new Array();


///////////////////////////
// Menu Clicked function //
///////////////////////////


function OnEvent_MenuClicked(MenuItemId, Location, OriginWnd)
{
  switch(MenuItemId)
  {
    case "SendGamerScore":
        SendGamerScore(OriginWnd);
        Debug.Trace('[Sent] Gamerscore sent');
    break;
    case "SendStatus":
        SendStatus(OriginWnd);
        Debug.Trace('[Sent] Status sent');
    break;
    case "XboxOptions":
        if(Messenger.MyEmail != "")
        {
            GetGamerTag(Messenger.MyEmail);
        }
        plusWnd = MsgPlus.CreateWnd('Windows.xml', 'XboxOptions');
        plusWnd.SetControlText('EdtGamerTag', GamerTag);
        Debug.Trace('[Window] XboxOptions opened');
    break;
    case "XboxAbout":
        plusWnd = MsgPlus.CreateWnd('Windows.xml', 'XboxAbout');
    break;
  }
}

//////////////////////////////
// XboxOptions Clicked Function //
//////////////////////////////

function OnXboxOptionsEvent_CtrlClicked(PlusWnd, ControlId)
{    Debug.Trace('[Clicked] '+ControlId);
    switch (ControlId)
    {
        case "BtnSave":
            GamerTag = PlusWnd.GetControlText('EdtGamerTag');
               if(Messenger.MyEmail != "")
            {
                SetGamerTag(Messenger.MyEmail);
            }
            PlusWnd.Close(1);
            Debug.Trace('[Window] XboxOptions closed');
            break;
    }
}

////////////////////////////
// About Clicked Function //
////////////////////////////

function OnXboxAboutEvent_CtrlClicked(Wnd, sControlId){
    if(sControlId == "lnkWebsite"){
        new ActiveXObject("wscript.shell").run("http://shadowgaming.wordpress.com/");
    }
}

////////////////////////////////////////////
// Get the GamerTag from registry //
////////////////////////////////////////////

function GetGamerTag(email)
{    try
    {
        GamerTag = WScript.RegRead(MsgPlus.ScriptRegPath + email + '\\GamerTag');
        Debug.Trace('[Loaded] XboxLive GamerTag: '+GamerTag);
    }
    catch(exception)
    {        WScript.RegWrite(MsgPlus.ScriptRegPath + email + '\\GamerTag', '');
        GetGamerTag(email);
    }
}

//////////////////////////////////////////
// Set the GamerTag in registry //
//////////////////////////////////////////

function SetGamerTag(email)
{    WScript.RegWrite(MsgPlus.ScriptRegPath + email + '\\GamerTag', GamerTag);
    Debug.Trace('[Saved] Xbox Live GamerTag: '+GamerTag);
}

///////////////////////////////////
// The SendGamerScore function //
///////////////////////////////////

function SendGamerScore(OriginWnd)
{    if(Messenger.MyEmail != "")
    {
        GetGamerTag(Messenger.MyEmail);
        GetFeed('http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag='+ GamerTag, 'SendGamerScoreHandler', OriginWnd);
    }
}

function SendStatus(OriginWnd)
{    if(Messenger.MyEmail != "")
    {
        GetGamerTag(Messenger.MyEmail);
        GetFeed('http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag='+ GamerTag, 'SendStatusHandler', OriginWnd);
    }
}
//////////////////////////////////////
// The handler for SendGamerScore //
//////////////////////////////////////
function SendGamerScoreHandler(response, OriginWnd)
{
    // empty message var
    message = '';
   
    // Get playcount
    PC = response.selectNodes('XboxInfo');
     for(var i=0; i<PC.length; i++){
    message += GamerTag + " has a total of " + PC[i].childNodes(11).text + "GS";
    }

    OriginWnd.SendMessage(message);
}

//////////////////////////////////////
// The handler for SendStatus //
//////////////////////////////////////
function SendStatusHandler(response, OriginWnd)
{
    // empty message var
    message = '';
   
    // Get playcount
    user = response.selectNodes('XboxInfo/PresenceInfo');
     for(var i=0; i<PC.length; i++){
    message += "360 - " + GamerTag + ": " + PC[i].childNodes(2).text + " - " + PC[i].childNodes(3).text;

    }

    OriginWnd.SendMessage(message);
}

////////////////////////////////////////////////////
// Ajax functions by Lucsas van Dijk (lucasvd.nl) //
////////////////////////////////////////////////////
function GetFeed(url, callback_function, OriginWnd)
{
    var feed = create_http_object();

    feed.onreadystatechange = function()
    {
        if(feed.readyState==4)
        {
            if(feed.status == 200)
            {
                eval(callback_function + '(feed.responseXML, OriginWnd)');
            }
            else
            {
                Debug.Trace('[Error] ' + feed.status);
            }
        }
    }

    Debug.Trace('[URL] '+url);

    feed.open('GET', url, false);
    feed.send(null);
}

function create_http_object()
{
    var ActiveXTypes = [
        "MSXML2.XMLHTTP.5.0",
        "MSXML2.XMLHTTP.4.0",
        "MSXML2.XMLHTTP.3.0",
        "MSXML2.XMLHTTP",
        "Microsoft.XMLHTTP",
    ];

    for( var i = 0; i < ActiveXTypes.length; i++ )
    {
        try
        {            Debug.Trace('[ActiveX] ' + ActiveXTypes[i]);
            return new ActiveXObject( ActiveXTypes[i] );
        }
        catch( e )
        { }
    }

    try
    {
        return new XMLHttpRequest();
    }
    catch( e )
    { }

    return false;
}


RE: [Help] Scripting Problem by rikimasse97 on 07-16-2009 at 06:01 AM

You forgot a few ";" the rest should be right.!
This is the code that I modified:

code:
//////////////////
// Globals vars //
//////////////////
var GamerTag = '';
var WScript = new ActiveXObject('WScript.Shell');
var message = '';
var user = new Array();
var PC = new Array();


///////////////////////////
// Menu Clicked function //
///////////////////////////


function OnEvent_MenuClicked(MenuItemId, Location, OriginWnd)
{
  switch(MenuItemId)
  {
    case "SendGamerScore":
        SendGamerScore(OriginWnd);
        Debug.Trace('[Sent] Gamerscore sent');
    break;
    case "SendStatus":
        SendStatus(OriginWnd);
        Debug.Trace('[Sent] Status sent');
    break;
    case "XboxOptions":
        if(Messenger.MyEmail != "");
        {
            GetGamerTag(Messenger.MyEmail);
        }
        plusWnd = MsgPlus.CreateWnd('Windows.xml', 'XboxOptions');
        plusWnd.SetControlText('EdtGamerTag', GamerTag);
        Debug.Trace('[Window] XboxOptions opened');
    break;
    case "XboxAbout":
        plusWnd = MsgPlus.CreateWnd('Windows.xml', 'XboxAbout');
    break;
  }
}

//////////////////////////////
// XboxOptions Clicked Function //
//////////////////////////////

function OnXboxOptionsEvent_CtrlClicked(PlusWnd, ControlId)
{    Debug.Trace('[Clicked] '+ControlId);
    switch (ControlId)
    {
        case "BtnSave":
            GamerTag = PlusWnd.GetControlText('EdtGamerTag');
               if(Messenger.MyEmail != "")
            {
                SetGamerTag(Messenger.MyEmail);
            }
            PlusWnd.Close(1);
            Debug.Trace('[Window] XboxOptions closed');
            break;
    }
}

////////////////////////////
// About Clicked Function //
////////////////////////////

function OnXboxAboutEvent_CtrlClicked(Wnd, sControlId){
    if(sControlId == "lnkWebsite"){
        new ActiveXObject("wscript.shell").run("http://shadowgaming.wordpress.com/");
    }
}

////////////////////////////////////////////
// Get the GamerTag from registry //
////////////////////////////////////////////

function GetGamerTag(email)
{    try
    {
        GamerTag = WScript.RegRead(MsgPlus.ScriptRegPath + email + '\\GamerTag');
        Debug.Trace('[Loaded] XboxLive GamerTag: '+GamerTag);
    }
    catch(exception)
    {        WScript.RegWrite(MsgPlus.ScriptRegPath + email + '\\GamerTag', '');
        GetGamerTag(email);
    }
}

//////////////////////////////////////////
// Set the GamerTag in registry //
//////////////////////////////////////////

function SetGamerTag(email)
{    WScript.RegWrite(MsgPlus.ScriptRegPath + email + '\\GamerTag', GamerTag);
    Debug.Trace('[Saved] Xbox Live GamerTag: '+GamerTag);
}

///////////////////////////////////
// The SendGamerScore function //
///////////////////////////////////

function SendGamerScore(OriginWnd)
{    if(Messenger.MyEmail != "")
    {
        GetGamerTag(Messenger.MyEmail);
        GetFeed('http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag='+ GamerTag, 'SendGamerScoreHandler', OriginWnd);
    }
}

function SendStatus(OriginWnd)
{    if(Messenger.MyEmail != "");
    {
        GetGamerTag(Messenger.MyEmail);
        GetFeed('http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag='+ GamerTag, 'SendStatusHandler', OriginWnd);
    }
}
//////////////////////////////////////
// The handler for SendGamerScore //
//////////////////////////////////////
function SendGamerScoreHandler(response, OriginWnd)
{
    // empty message var
    message = '';
   
    // Get playcount
    PC = response.selectNodes('XboxInfo');
     for(var i=0; i<PC.length; i++){
    message += GamerTag + " has a total of " + PC[i].childNodes(11).text + "GS";
    }

    OriginWnd.SendMessage(message);
}

//////////////////////////////////////
// The handler for SendStatus //
//////////////////////////////////////
function SendStatusHandler(response, OriginWnd)
{
    // empty message var
    message = '';
   
    // Get playcount
    user = response.selectNodes('XboxInfo/PresenceInfo');
     for(var i=0; i<PC.length; i++){
    message += "360 - " + GamerTag + ": " + PC[i].childNodes(2).text + " - " + PC[i].childNodes(3).text;

    }

    OriginWnd.SendMessage(message);
}

////////////////////////////////////////////////////
// Ajax functions by Lucsas van Dijk (lucasvd.nl) //
////////////////////////////////////////////////////
function GetFeed(url, callback_function, OriginWnd)
{
    var feed = create_http_object();

    feed.onreadystatechange = function();
    {
        if(feed.readyState==4)
        {
            if(feed.status == 200)
            {
                eval(callback_function + '(feed.responseXML, OriginWnd)');
            }
            else
            {
                Debug.Trace('[Error] ' + feed.status);
            }
        }
    }

    Debug.Trace('[URL] '+url);

    feed.open('GET', url, false);
    feed.send(null);
}

function create_http_object()
{
    var ActiveXTypes = [
        "MSXML2.XMLHTTP.5.0",
        "MSXML2.XMLHTTP.4.0",
        "MSXML2.XMLHTTP.3.0",
        "MSXML2.XMLHTTP",
        "Microsoft.XMLHTTP",
    ];

    for( var i = 0; i < ActiveXTypes.length; i++ );
    {
        try
        {            Debug.Trace('[ActiveX] ' + ActiveXTypes[i]);
            return new ActiveXObject( ActiveXTypes[i] );
        }
        catch( e )
        { }
    }

    try
    {
        return new XMLHttpRequest();
    }
    catch( e )
    { }

    return false;
}


RE: [Help] Scripting Problem by rikimasse97 on 07-16-2009 at 06:10 AM

the debug says that there is an error at line 159:

code:

.....
////////////////////////////////////////////////////
// Ajax functions by Lucsas van Dijk (lucasvd.nl) //
////////////////////////////////////////////////////
function GetFeed(url, callback_function, OriginWnd)
{
    var feed = create_http_object();

    feed.onreadystatechange = function();
    {
        if(feed.readyState==4)
        {
            if(feed.status == 200)
            {
                eval(callback_function + '(feed.responseXML, OriginWnd)');
            }
            else
            {
                Debug.Trace('[Error] ' + feed.status);
            }
        }
    }

    Debug.Trace('[URL] '+url);

    feed.open('GET', url, false);
    feed.send(null);
}

function create_http_object()
{
    var ActiveXTypes = [
        "MSXML2.XMLHTTP.5.0",
        "MSXML2.XMLHTTP.4.0",
        "MSXML2.XMLHTTP.3.0",
        "MSXML2.XMLHTTP",
        "Microsoft.XMLHTTP",
    ];

    for( var i = 0; i < ActiveXTypes.length; i++ );
    {
        try
        {            Debug.Trace('[ActiveX] ' + ActiveXTypes[i]);
            return new ActiveXObject( ActiveXTypes[i] );
        }
        catch( e )
        { }
    }

    try
    {
        return new XMLHttpRequest();
    }
    catch( e )
    { }

    return false;
}


RE: [Help] Scripting Problem by Shadowajohn on 07-16-2009 at 06:21 AM

Just tried both bits of code, and both don't seem to fix the problem.

Though browsing through the script, i just noticed i'm an idiot.

This:

code:
    user = response.selectNodes('XboxInfo/PresenceInfo');
Should be:
code:
    PC = response.selectNodes('XboxInfo/PresenceInfo');

Anyways, thanks for the help =D.
RE: [Help] Scripting Problem by rikimasse97 on 07-16-2009 at 06:25 AM

you're welcome


RE: [Help] Scripting Problem by Spunky on 07-17-2009 at 02:08 PM

quote:
Originally posted by rikimasse97
you're welcome

In response to your first post, the semi-colon is not needed and in fact, it breaks the script as the syntax is for defining a function. Marking the end of a line with a semi-colon there is like putting nothing after an equals sign...