Shoutbox

Uptime script, why doesn't it work? - 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: Uptime script, why doesn't it work? (/showthread.php?tid=66340)

Uptime script, why doesn't it work? by CrAzY_KeBaB on 09-16-2006 at 10:07 PM

Why doesn't this script work? Please ceck it thorugh for me. Thanks in advance, Chris.

code:
function OnEvent_Initialize(MessengerStart)
{
    MsgPlus.DisplayToast("P.M. Time", "Displays uptime as personal message.");
    var s=0,m=0,h=0,d=0;
    MsgPlus.AddTimer("second", 1000);
}

function OnEvent_Timer("second")
{
    if(id=="second")
    {
        s+s+1;
        if (s==60)
        {
            s=0;
            m=m+1;
        }
        if (m==60)
        {
            m=0;
            h=h+1;
        }
        if (h==24)
        {
            h=0;
            d=d+1;
        }
        if (m==0)
        {
            uptime="Time Online: " + s + " Seconds";
        }
        if (h==0)
        {
            uptime="Time Online: " + m + " Minutes, " + s + " Seconds";
        }
        if (d==0)
        {
            uptime="Time Online: " + h + " Hours, " + m + " Minutes, " + s + " Seconds";
        }
        if (d!=0)
        {
            uptime="Time Online: " + d + " Days, " + h + " Hours, " + m + " Minutes, " + s + " Seconds";
        }
        Messenger.MyPersonalMessage=uptime;
        MsgPlus.AddTimer("second", 1000);
    }
}


RE: Uptime script, why doesn't it work? by Silentdragon on 09-16-2006 at 10:29 PM

At first glance I see that you put a string in the function OnTimer when it should be a variable.

code:
function OnEvent_Timer("second")
should be
code:
function OnEvent_Timer(id)

Next you declare the the time variables in initialize which would make them local, declare them as global ones by putting their declartion outside a function

code:
    var s=0,m=0,h=0,d=0;
function OnEvent_Initialize(MessengerStart)
{
    MsgPlus.DisplayToast("P.M. Time", "Displays uptime as personal message.");
....

RE: Uptime script, why doesn't it work? by CrAzY_KeBaB on 09-16-2006 at 11:00 PM

Now, it simply stays on Time Online: 0 Hours, 0 Mins, 0 Seconds

What have i done wrong?

code:
var s=0,m=0,h=0,d=0;

function OnEvent_Initialize(MessengerStart)
{
    MsgPlus.DisplayToast("P.M. Time", "Displays uptime as personal message.");
    MsgPlus.AddTimer("second", 1000);
}

function OnEvent_Timer(id)
{
    if(id=="second")
    {
        s+s+1;
        if (s==60)
        {
            s=0;
            m=m+1;
        }
        if (m==60)
        {
            m=0;
            h=h+1;
        }
        if (h==24)
        {
            h=0;
            d=d+1;
        }
        if (m==0)
        {
            uptime="Time Online: " + s + " Seconds";
        }
        if (h==0)
        {
            uptime="Time Online: " + m + " Minutes, " + s + " Seconds";
        }
        if (d==0)
        {
            uptime="Time Online: " + h + " Hours, " + m + " Minutes, " + s + " Seconds";
        }
        if (d!=0)
        {
            uptime="Time Online: " + d + " Days, " + h + " Hours, " + m + " Minutes, " + s + " Seconds";
        }
        Messenger.MyPersonalMessage=uptime;
        MsgPlus.AddTimer("second", 1000);
    }
}


RE: Uptime script, why doesn't it work? by Silentdragon on 09-16-2006 at 11:13 PM

code:
s+s+1;
You typo-ed
code:
s=s+1;
Although you could just change all x=x+1
to x++
RE: Uptime script, why doesn't it work? by CookieRevised on 09-17-2006 at 12:18 AM

Besides the errors shown in the previous posts, there are some other things going on which you need to fix and/or consider:

  1. Do NOT change the PSM every second. Not only will this trigger the messenger server's flood protection and thus it will not work anymore after a while, it is also highly annoying to your contacts. Change the PSM every minute or so...

  2. Read this post regarding the use of timers in scripts!!:
    http://shoutbox.menthix.net/showthread.php?tid=66...d=729576#pid729576

    problem 1) the timer is still triggered whenever another user signs in to messenger, and thus the PSM of that unexpecting user will be changed.

    problem 2) the timer is still triggered even if the user isn't logged in to messenger (offline), which will result in an error since you can't change the PSM in that case.

  3. Instead of triggering the timer each second and manually counting up the different time variables, why not simply get the system date/time when the user signs in. And when you are going to change the PSM (eg: every minute) grab the system date/time again and calculate the difference with the previous value.

    In that way you reduce the overhead and constant triggering of the timer which you now have. And you also don't need those (global) time variables anymore.

    (in fact as the script is now, you don't need all those time variables to be global either, just the seconds must be global, the rest can be calculated from that number (which will also reduce the need of those IF checks and resetting the values etc))

  4. Very minor: if you only use 1 timer you don't need to check the timer id in the OnEvent_Timer function.

  5. You actually don't need to calculate the PC uptime yourself. The uptime can be grabbed from Windows itself as done in following script: [Release] UptimePms

    upsfeup uses a Windows API for this (this script is a dedicated uptime script; the purpose is only to show the uptime in your PSM, including a GUI and options to format the actual string). It does exactly what you want I think.

    Then there is also the Computer Details script from dt, but that currently has a bug in its uptime routine.

    And there are also other threads about uptime scripts. eg:
    online time script
    etc...