Shoutbox

Help! (script 'freezes') - 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! (script 'freezes') (/showthread.php?tid=71008)

Help! (script 'freezes') by mad_willsy on 01-24-2007 at 05:52 PM

I have adapted one of the scripts to show what I'm playing in SAM BC.

As one of SAM's featurs, you can write the currently playing song to a xml file.

When i skip lots of songs successevly the script 'freezes' and refuses to change my PM!

Here's the source:

code:

var version
var status;
var timer;
var sentenceArray;
var copySentenceArray;
var editingSentence;
var file;
var XMLDoc;




function OnEvent_Initialize(MessengerStart)
{
}


function OnEvent_Uninitialize(MessengerExit)
{
}


function OnEvent_Timer (timerId){   
}


function OnEvent_Signin(){
    //Create the xml filepath.
    file = MsgPlus.ScriptFilesPath + "\\output.xml";
    //Load the status of the script and the list of messages.
    XMLDoc = new ActiveXObject("Microsoft.XMLDOM");
    XMLDoc.async = false;
    XMLDoc.load(file);
    //Load values from the xml file.
    version = XMLDoc.getElementsByTagName("version");
    timer = XMLDoc.getElementsByTagName("timer");
    sentenceArray = XMLDoc.getElementsByTagName("sentence");
    Messenger.MyPersonalMessage  = sentenceArray[Math.floor(Math.random()*sentenceArray.length)].text;
    MsgPlus.AddTimer("MessagesTimer", (parseInt(timer[0].text))*1000);
}


function setTimer(){
    //Create the timer to change the personal message.
    MsgPlus.AddTimer("MessagesTimer", (parseInt(timer[0].text))*1000);
}
   
function OnEvent_Timer (timerId){
    //Create the xml filepath.
    file = MsgPlus.ScriptFilesPath + "\\output.xml";
    //Load the status of the script and the list of messages.
    XMLDoc = new ActiveXObject("Microsoft.XMLDOM");
    XMLDoc.async = false;
    XMLDoc.load(file);
    //Load values from the xml file.
    version = XMLDoc.getElementsByTagName("version");
    timer = XMLDoc.getElementsByTagName("timer");
    sentenceArray = XMLDoc.getElementsByTagName("sentence");
    Messenger.MyPersonalMessage = sentenceArray[Math.floor(Math.random()*sentenceArray.length)].text;
    MsgPlus.AddTimer("MessagesTimer", (parseInt(timer[0].text))*1000);
}
function OnEvent_MenuClicked (MenuItemId, Location, OriginWnd){
    if (MenuItemId=="on") sbcOn();
    if (MenuItemId=="off") sbcOff();
    }
function sbcOff(){
MsgPlus.CancelTimer("MessagesTimer");
Messenger.MyPersonalMessage = "";
}
function sbcOn(){
Messenger.MyPersonalMessage  = sentenceArray[Math.floor(Math.random()*sentenceArray.length)].text;
MsgPlus.AddTimer("MessagesTimer", (parseInt(timer[0].text))*1000);
}


If you need any of the other files (i.e. xml input, xml output etc) - let me know
I have a terrible habit of doing this! - Problem has been solved (still a minor problem at bottom) by downloading a load of scripts and 'bundeling' the bits together!

Here's all the files -

sambc.js
code:

var version;
var status;
var timer;
var artist;
var title;
var played;
var sentenceArray;
var copySentenceArray;
var editingSentence;
var file;
var XMLDoc;


function setNowPlaying(enabled, type, format, title, artist, album, contentID){
    if(typeof(type) == "undefined")type = "Music";
    if(typeof(format) == "undefined")format = "";
    if(typeof(title) == "undefined")title = "";
    if(typeof(artist) == "undefined")artist = "";
    if(typeof(album) == "undefined")album = "";
    if(typeof(contentID) == "undefined")contentID = "";
    enabled = Math.abs(enabled);
   
    var WM_COPYDATA = 0x4A;
   
    //reference
    var song = Interop.Allocate(512);
   
    //change the Music thing to Games or Office or
    song.WriteString(0, "\\0" + type + "\\0" + enabled + "\\0" + format +"\\0" + title +"\\0" + artist + "\\0" + album + "\\0" + contentID + "\\0");
   
   
    //write our copyDataStruct Structure
    var copyDataStruct = Interop.Allocate(12);
    copyDataStruct.WriteDWORD(0, 0x547); //dwData
    copyDataStruct.WriteDWORD(4, song.Size); //cbData
    copyDataStruct.WriteDWORD(8, song.DataPtr);  //lpData
   
   
    //Send it to all open messengers
    var hMSGRUI = 0;
    do{
        hMSGRUI = Interop.Call("User32", "FindWindowExW", 0, hMSGRUI, "MsnMsgrUIManager", 0);
        if(hMSGRUI > 0){
            Interop.Call("User32", "SendMessageW", hMSGRUI, WM_COPYDATA, 0, copyDataStruct);   
        }
    }while(hMSGRUI != 0);
}


function OnEvent_Initialize(MessengerStart)
{
}


function OnEvent_Uninitialize(MessengerExit)
{
}


function OnEvent_Timer (timerId){   
}


function OnEvent_Signin(){
    //Create the xml filepath.
    MsgPlus.AddTimer("MessagesTimer", 4000);
    file = MsgPlus.ScriptFilesPath + "\\output.xml";
    //Load the status of the script and the list of messages.
    XMLDoc = new ActiveXObject("Microsoft.XMLDOM");
    XMLDoc.async = false;
    XMLDoc.load(file);
    //Load values from the xml file.
    version = XMLDoc.getElementsByTagName("version");
    timer = XMLDoc.getElementsByTagName("timer");
    artist = XMLDoc.getElementsByTagName("artist");
    title = XMLDoc.getElementsByTagName("title");
    played = XMLDoc.getElementsByTagName("played");
    setNowPlaying(true, "Music", "{0} - {1}", artist[Math.floor(Math.random()*artist.length)].text, title[Math.floor(Math.random()*title.length)].text + " - " + played[Math.floor(Math.random()*played.length)].text);
}


function setTimer(){
    //Create the timer to change the personal message.
    MsgPlus.AddTimer("MessagesTimer", 4000);
}
   
function OnEvent_Timer (timerId){
    //Create the xml filepath.
    MsgPlus.AddTimer("MessagesTimer", 4000);
    file = MsgPlus.ScriptFilesPath + "\\output.xml";
    //Load the status of the script and the list of messages.
    XMLDoc = new ActiveXObject("Microsoft.XMLDOM");
    XMLDoc.async = false;
    XMLDoc.load(file);
    //Load values from the xml file.
    version = XMLDoc.getElementsByTagName("version");
    timer = XMLDoc.getElementsByTagName("timer");
    artist = XMLDoc.getElementsByTagName("artist");
    title = XMLDoc.getElementsByTagName("title");
    played = XMLDoc.getElementsByTagName("played");
    setNowPlaying(true, "Music", "{0} - {1}", artist[Math.floor(Math.random()*artist.length)].text, title[Math.floor(Math.random()*title.length)].text + " - " + played[Math.floor(Math.random()*played.length)].text);
}
function OnEvent_MenuClicked (MenuItemId, Location, OriginWnd){
    if (MenuItemId=="reset") sbcOn();
    }
function sbcOff(){
MsgPlus.CancelTimer("MessagesTimer");
setNowPlaying(false);
}
function sbcOn(){
    //Create the xml filepath.
    MsgPlus.AddTimer("MessagesTimer", 4000);
    file = MsgPlus.ScriptFilesPath + "\\output.xml";
    //Load the status of the script and the list of messages.
    XMLDoc = new ActiveXObject("Microsoft.XMLDOM");
    XMLDoc.async = false;
    XMLDoc.load(file);
    //Load values from the xml file.
    version = XMLDoc.getElementsByTagName("version");
    timer = XMLDoc.getElementsByTagName("timer");
    artist = XMLDoc.getElementsByTagName("artist");
    title = XMLDoc.getElementsByTagName("title");
    played = XMLDoc.getElementsByTagName("played");
    setNowPlaying(true, "Music", "{0} - {1}", artist[Math.floor(Math.random()*artist.length)].text, title[Math.floor(Math.random()*title.length)].text + " - " + played[Math.floor(Math.random()*played.length)].text);
}


input.xml
code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
    <version>1.2</version>
    <status>ON</status>
    <timer>5</timer>
    <artist>$song.artist$</artist>
    <title>$song.title$ [$song.mmss$]</title>
    <played>Played $song.count_played$ times</played>
    </root>


output.xml (empty - SAM BC fills this in using input.xml)

ScriptInfo.xml
code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ScriptInfo xmlns="urn:msgplus:scripts" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <Information>
        <Name>SAM BC - Now Playing</Name>
        <Description>Gets Now playing information from xml file!</Description>
    </Information>

    <ScriptMenu>
        <MenuEntry Id="reset">Force Update!</MenuEntry>
    </ScriptMenu>
</ScriptInfo>


I'm sure this could be adapted to help with somebody else's problem!

PROBLEM:
What I would still like to do is add 1 to where I have this:
played[Math.floor(Math.random()*played.length)].text

Also I could easily adapt the xml file to store the filename in say:
<played>$song.filename$</played>

Could I use this so when my contact says...
!sendfile
...it sends the file, getting the file location from the xml file! (The FULL path would be stored!)