What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Uptime script, why doesn't it work?

Uptime script, why doesn't it work?
Author: Message:
CrAzY_KeBaB
New Member
*


Posts: 6
Joined: Sep 2006
O.P. Uptime script, why doesn't it work?
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);
    }
}

09-16-2006 10:07 PM
Profile E-Mail PM Find Quote Report
Silentdragon
Full Member
***

Avatar
if(life==null && wrists) EmoAlert();

Posts: 148
Reputation: 2
34 / Male / –
Joined: Jun 2006
RE: Uptime script, why doesn't it work?
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.");
....
09-16-2006 10:29 PM
Profile E-Mail PM Web Find Quote Report
CrAzY_KeBaB
New Member
*


Posts: 6
Joined: Sep 2006
O.P. RE: Uptime script, why doesn't it work?
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);
    }
}

09-16-2006 11:00 PM
Profile E-Mail PM Find Quote Report
Silentdragon
Full Member
***

Avatar
if(life==null && wrists) EmoAlert();

Posts: 148
Reputation: 2
34 / Male / –
Joined: Jun 2006
RE: Uptime script, why doesn't it work?
code:
s+s+1;
You typo-ed
code:
s=s+1;
Although you could just change all x=x+1
to x++

This post was edited on 09-16-2006 at 11:14 PM by Silentdragon.
09-16-2006 11:13 PM
Profile E-Mail PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Uptime script, why doesn't it work?
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...
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-17-2006 12:18 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On