Shoutbox

[HELP] I need some help with my script - 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] I need some help with my script (/showthread.php?tid=86599)

[HELP] I need some help with my script by Otacon on 10-12-2008 at 02:18 PM

OK, I made a script which reads text from a .txt file(amipOutput.txt) and sets it as my PM. In case that file is empty, it reads another file(PM.txt). And sets the text inside that as my PM. The script is working perfectly except for one thing: after some time of running, i get a "End of file" error in the debugger and the script stops. Here's my code:

quote:
var y = 0;
function OnEvent_Initialize(MessengerStart)
{
    addTimer();
}
function addTimer()
{
    MsgPlus.AddTimer("pm",1000);
}
function OnEvent_Timer(pm)
{
    if(y == 0)
    {
        var fso1, f, s;
        fso1 = new ActiveXObject("Scripting.FileSystemObject");
        f = fso1.GetFile("C:\\amipOutput.txt");
        s = f.size;
       
        if(s == 0)
        {
            setPm();
            addTimer();
        }
        else
        {
            setAmip();
            addTimer();
        }
       
    }
}
function setPm()
{
    var fso, ts, a, a1, f1, txt;
    var ForReading = 1;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    ts = fso.OpenTextFile("C:\\PM.txt",ForReading);
    a = ts.ReadAll();
    ts.Close();
    a = MsgPlus.RemoveFormatCodes(a);
    Messenger.MyPersonalMessage = a;
    a = 0;
}
function setAmip()
{
    var fso2, ts2, b, b1, f1, txt;
    var ForReading = 1;
    fso2 = new ActiveXObject("Scripting.FileSystemObject");
    ts2 = fso2.OpenTextFile("C:\\amipOutput.txt",ForReading);
    b = ts2.ReadAll();
    ts2.Close();
    b = MsgPlus.RemoveFormatCodes(b);
    Messenger.MyPersonalMessage = b;
    b = 0;
}
function OnEvent_MenuClicked(sMenuId, sLoc, sWnd)
{
    if(sMenuId=="on")
    {
        addTimer();
        var y = 0;
    }
    if(sMenuId=="off")
    {
        var y = 1;
        MsgPlus.CancelTimer("pm");
        setPm();
    }
}


function OnGetScriptMenu()
{

    var myMenu = new PlusMenu;
   
    myMenu.addItem("on", "Turn AMIP PM on");
    myMenu.addItem("off", "Turn AMIP PM off");
   
    return myMenu.build();
}

Please, it's driving me crazy, I want to finally get it to work.
RE: [HELP] I need some help with my script by Jonte135 on 10-18-2008 at 03:52 PM

Try adding a loop perhaps? ^o)


RE: [HELP] I need some help with my script by Matti on 10-18-2008 at 04:05 PM

"ForReading" is a constant, but it isn't defined in Plus! scripts. You'll have to assign its value yourself at the very top of your script, so add:

code:
var ForReading = 1
at the top of your script.

But more important: a timer interval of 1000 is waaay too low! No wonder you end up with troubles, because:
  1. Messenger itself doesn't allow you to update it that frequently. Okay, it may look like it works, but it won't actually update on the servers.
  2. the file is being read too often! Every second, it has to be opened, read and closed again. That's just way too much.
My recommendation: change the interval. Make it at least 15 seconds (15000 milliseconds) or, to spare your contacts from flooding their logs with your personal message updates, make it one minute (60000 ms) or more. There should really be no reason to update your PSM that often.
RE: [HELP] I need some help with my script by Otacon on 10-18-2008 at 04:14 PM

Thanks for the help, much appreciated, will test it now. The reason for the low interval is that the first file that is read is actually a output file from AMIP, a iTunes plugin that writes what I'm currently listening to. So what I wanted to do is make the script look for changes in that files every second in case I change the song I'm listening to. For that purpose, one minute is just too much, but if I still have problems, I guess that will be the only way to solve it.

Anyways, thanks for all the help.


RE: [HELP] I need some help with my script by Matti on 10-18-2008 at 04:19 PM

If you want to display what you're playing in iTunes, why don't you simply use this script: [release] Music now playing? That script gets the information directly from iTunes, without the need of a plug-in who writes the information to a file first.

I mean: why would you want to re-invent the wheel? :P Give it a try and see how it works out for you. :)


RE: [HELP] I need some help with my script by Otacon on 10-18-2008 at 06:14 PM

Already tried that, didn't work. Messenger Live comes with a integrated plugin for iTunes, and that plugin overwrites any custom input from third-party addons or programs. This approach allows me to have a customized Now Playing status, because it sets my Now Playing status as a regular personal message, so the Live Messenger plugin has nothing to do with it. It would work great if only I could find out what the problem is.

Still can't get it to work, though. Tried setting the delay to 1 minute and tried adding "var ForReading = 1" at the beginning of the script, and I still get the same error. Any more ideas?