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 |
|
|
Silentdragon
Full Member
if(life==null && wrists) EmoAlert();
Posts: 148 Reputation: 2
34 / / –
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 |
|
|
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 |
|
|
Silentdragon
Full Member
if(life==null && wrists) EmoAlert();
Posts: 148 Reputation: 2
34 / / –
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 |
|
|
CookieRevised
Elite Member
Posts: 15517 Reputation: 173
– / /
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:
- 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...
- 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.
- 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))
- Very minor: if you only use 1 timer you don't need to check the timer id in the OnEvent_Timer function.
- 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 |
|
|
|
|