What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Countdown stops when close MSN

Countdown stops when close MSN
Author: Message:
SnuZZer
Full Member
***

Avatar

Posts: 114
32 / Male / Flag
Joined: Jun 2006
O.P. Countdown stops when close MSN
Hi.
I have made a script which makes a countdown in my personal message. It works until I close messenger - not log out - close.
When I close it and open it again my countdown stops, but when i log out and log in my countdown works fine.

It is written on danish, but i have you understand what the variables contains ;-)

Here is my code:
code:
function OnEvent_SignIn(Email)
{
    Opdater();
}

function Opdater()
{
    if(Status == "til")
    {
        var Idag = new Date();
        var Dato = new Date(gemAar,gemMaaned - 1,gemDag);
       
        if(Idag >= Dato)
        {
            Messenger.MyPersonalMessage = gemEfterBegivenhed;
        }
        else
        {
            Dato.setHours(gemTimer);
            Dato.setMinutes(gemMinutter);

            var Forskel = Dato.getTime() - Idag.getTime();
   
            var dageForskel = Math.floor(Forskel/1000/60/60/24);
            Forskel -= dageForskel*1000*60*60*24
   
            var timerForskel = Math.floor(Forskel/1000/60/60);
            Forskel -= timerForskel*1000*60*60
   
            var minutterForskel = Math.floor(Forskel/1000/60);
            Forskel -= minutterForskel*1000*60
   
            var sekunderForskel = Math.floor(Forskel/1000);
   
            if(dageForskel == "1")
            {
                var visDage = "dag";
            }
            else
            {
                var visDage = "dage";
            }

            if(timerForskel == "1")
            {
                var visTimer = "time";
            }
            else
            {
                var visTimer = "timer";
            }

            if(minutterForskel == "1")
            {
                var visMinutter = "minut";
            }
            else
            {
                var visMinutter = "minutter";
            }
   
            if(sekunderForskel == "1")
            {
                var visSekunder = "sekund";
            }
            else
            {
                var visSekunder = "sekunder";
            }
   
            Messenger.MyPersonalMessage = dageForskel + " " + visDage + ", " + timerForskel + " " + visTimer + ", " + minutterForskel + " " + visMinutter + " og " + sekunderForskel + " " + visSekunder + gemBegivenhed;
   
            MsgPlus.AddTimer("OpdaterDato",1000);
        }
    }
}

function OnEvent_Timer(Id)
{
    if(Id = "OpdaterDato")
    {
        Opdater();
    }
}

function Vindue()
{
    Popup = MsgPlus.CreateWnd("vindue.xml","WndMain");
    try {
        var x = shell.RegRead(regPath+"Top");
    }
    catch(e) {}
    if (x == 1) {
        Interop.Call("User32.dll","SetWindowPos",Popup.Handle,-1,0,0,0,0,19);Popup.Button_SetCheckState("Chk",true);
    }
}

function OnGetScriptMenu(Location)
{
    ScriptMenu = "<ScriptMenu>";
    ScriptMenu += "<MenuEntry Id=\"indstillinger\">";
    ScriptMenu += "Indstillinger";
    ScriptMenu += "</MenuEntry>";
    ScriptMenu += "<MenuEntry Id=\"tilfra\">";
    ScriptMenu += "Slå til/fra";
    ScriptMenu += "</MenuEntry>";
    ScriptMenu += "</ScriptMenu>";
    return ScriptMenu;
}

function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd)
{
    switch(MenuItemId)
    {
        case "indstillinger":
            try {var x = Wnd_.Handle;};catch(e) {}
            if (x == null){
                Vindue();
            }
            break;
        case "tilfra":
            if(Status == "til")
            {
                Status = "fra";
                Messenger.MyPersonalMessage = oprindeligPb;
                MsgPlus.DisplayToast("Nedtælling","Nedtælling er slået fra.");
            }
            else
            {
                Status = "til";
                Opdater();
                MsgPlus.DisplayToast("Nedtælling","Nedtælling er slået til.");
            }
            break;
    }
}

function OnWndMainEvent_CtrlClicked(Wnd, Handling)
{
    switch(Handling)
    {
        case "knap_gem":
            gemDag = Wnd.GetControlText("input_dag");
            gemMaaned = Wnd.GetControlText("input_maaned");
            gemAar = Wnd.GetControlText("input_aar");
            gemTimer = Wnd.GetControlText("input_timer");
            gemMinutter = Wnd.GetControlText("input_minutter");
            gemBegivenhed = Wnd.GetControlText("input_begivenhed");
            gemEfterBegivenhed = Wnd.GetControlText("input_efterBegivenhed");
            Status = "til";
            Opdater();
            Wnd.Close(0);
            break;
        case "knap_luk":
            Wnd.Close(0);
            break;
    }
}

Thanks in advance.
- Simon
11-30-2006 06:48 AM
Profile E-Mail PM Web Find Quote Report
NiteMare
Veteran Member
*****

Avatar
Giga-Byte me

Posts: 2497
Reputation: 37
37 / Male / Flag
Joined: Aug 2003
RE: Countdown stops when close MSN
you do know there are several other scripts that do this already... such as mine [Release] CountDown [Update: Version 2.9.0]
[Image: sig/]
I'll never forget what she said 6861 days, 21 hours, 57 minutes, 27 seconds ago
Need hosting? Check
out my website. we can help you out :)
11-30-2006 06:58 AM
Profile PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: Countdown stops when close MSN
quote:
Originally posted by NiteMare
you do know there are several other scripts that do this already... such as mine [Release] CountDown [Update: Version 2.9.0]
...just as "Countdown Live" and "Holiday Counter"...
see CookieRevised's reply to Countdown for PSM/Nick...

please list them _all_...

And he's not looking for a script, he's trying to create one himself to learn.


quote:
Originally posted by SnuZZer
Hi.
I have made a script which makes a countdown in my personal message. It works until I close messenger - not log out - close.
When I close it and open it again my countdown stops, but when i log out and log in my countdown works fine.

It is written on danish, but i have you understand what the variables contains ;-)
A script does not stop when you sign out of Messenger. When you sign out, the script still keeps running, after the OnEvent_SignOut() is fired.

When you close Messenger, Messenger Plus! and also scripts will be closed too...

There are many errors in the code though.

For starters you use some same variables in different function, but you nowhere defined these global variables. If you don't define a global variable, they will not work. eg: the Status variable.


PS: again this is a not so easy concept/script you're trying todo. I would still suggest to make something easier for your first script. Like a script which changes what you write in a conversation. Or scripts which simply show some popups after entering a command in a conversation...

This post was edited on 11-30-2006 at 08:25 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
11-30-2006 08:15 AM
Profile PM Find Quote Report
SnuZZer
Full Member
***

Avatar

Posts: 114
32 / Male / Flag
Joined: Jun 2006
O.P. RE: Countdown stops when close MSN
Hi.
You mean that i must define the variables in the start of the code? - I have tried, it doesn't work.

I have made Messenger Plus! Scripts for a while, I'm ain't "hardcore-coder", but i'm not novice neither.

I have checked the CountDown [Update: Version 2.9.0] code, but that code just confuse me.
11-30-2006 01:52 PM
Profile E-Mail PM Web Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: Countdown stops when close MSN
quote:
Originally posted by SnuZZer
You mean that i must define the variables in the start of the code?

Doesn't have to be at the start as in the initialize event or whatever... They need to be defined OUTSIDE of any function...

eg:
code:
var myString;
var myObject = new Object();

function OnEvent_Initialize(){{
...
...
}
<Eljay> "Problems encountered: shit blew up" :zippy:
11-30-2006 02:13 PM
Profile PM Find Quote Report
SnuZZer
Full Member
***

Avatar

Posts: 114
32 / Male / Flag
Joined: Jun 2006
O.P. RE: Countdown stops when close MSN
Hi.
Like this?

code:
var gemDag;
var gemMaaned;
var gemAar;
var gemTimer;
var gemMinutter;
var gemBegivenhed;
var gemEfterBegivenhed;
var Status = "fra";

function OnEvent_SignIn(Email)
{
    Opdater();
}

function Opdater()
{
    if(Status == "til")
    {
        var Idag = new Date();
        var Dato = new Date(gemAar,gemMaaned - 1,gemDag);
       
        if(Idag >= Dato)
        {
            Messenger.MyPersonalMessage = gemEfterBegivenhed;
        }
        else
        {
            Dato.setHours(gemTimer);
            Dato.setMinutes(gemMinutter);

            var Forskel = Dato.getTime() - Idag.getTime();
   
            var dageForskel = Math.floor(Forskel/1000/60/60/24);
            Forskel -= dageForskel*1000*60*60*24
   
            var timerForskel = Math.floor(Forskel/1000/60/60);
            Forskel -= timerForskel*1000*60*60
   
            var minutterForskel = Math.floor(Forskel/1000/60);
            Forskel -= minutterForskel*1000*60
   
            var sekunderForskel = Math.floor(Forskel/1000);
   
            if(dageForskel == "1")
            {
                var visDage = "dag";
            }
            else
            {
                var visDage = "dage";
            }

            if(timerForskel == "1")
            {
                var visTimer = "time";
            }
            else
            {
                var visTimer = "timer";
            }

            if(minutterForskel == "1")
            {
                var visMinutter = "minut";
            }
            else
            {
                var visMinutter = "minutter";
            }
   
            if(sekunderForskel == "1")
            {
                var visSekunder = "sekund";
            }
            else
            {
                var visSekunder = "sekunder";
            }
   
            Messenger.MyPersonalMessage = dageForskel + " " + visDage + ", " + timerForskel + " " + visTimer + ", " + minutterForskel + " " + visMinutter + " og " + sekunderForskel + " " + visSekunder + gemBegivenhed;
   
            MsgPlus.AddTimer("OpdaterDato",1000);
        }
    }
}

function OnEvent_Timer(Id)
{
    if(Id = "OpdaterDato")
    {
        Opdater();
    }
}

function Vindue()
{
    Popup = MsgPlus.CreateWnd("vindue.xml","WndMain");
    try {
        var x = shell.RegRead(regPath+"Top");
    }
    catch(e) {}
    if (x == 1) {
        Interop.Call("User32.dll","SetWindowPos",Popup.Handle,-1,0,0,0,0,19);Popup.Button_SetCheckState("Chk",true);
    }
}

function OnGetScriptMenu(Location)
{
    ScriptMenu = "<ScriptMenu>";
    ScriptMenu += "<MenuEntry Id=\"indstillinger\">";
    ScriptMenu += "Indstillinger";
    ScriptMenu += "</MenuEntry>";
    ScriptMenu += "<MenuEntry Id=\"tilfra\">";
    ScriptMenu += "Slå til/fra";
    ScriptMenu += "</MenuEntry>";
    ScriptMenu += "</ScriptMenu>";
    return ScriptMenu;
}

function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd)
{
    switch(MenuItemId)
    {
        case "indstillinger":
            try {var x = Wnd_.Handle;};catch(e) {}
            if (x == null){
                Vindue();
            }
            break;
        case "tilfra":
            if(Status == "til")
            {
                Status = "fra";
                Messenger.MyPersonalMessage = oprindeligPb;
                MsgPlus.DisplayToast("Nedtælling","Nedtælling er slået fra.");
            }
            else
            {
                Status = "til";
                Opdater();
                MsgPlus.DisplayToast("Nedtælling","Nedtælling er slået til.");
            }
            break;
    }
}

function OnWndMainEvent_CtrlClicked(Wnd, Handling)
{
    switch(Handling)
    {
        case "knap_gem":
            gemDag = Wnd.GetControlText("input_dag");
            gemMaaned = Wnd.GetControlText("input_maaned");
            gemAar = Wnd.GetControlText("input_aar");
            gemTimer = Wnd.GetControlText("input_timer");
            gemMinutter = Wnd.GetControlText("input_minutter");
            gemBegivenhed = Wnd.GetControlText("input_begivenhed");
            gemEfterBegivenhed = Wnd.GetControlText("input_efterBegivenhed");
            Status = "til";
            Opdater();
            Wnd.Close(0);
            break;
        case "knap_luk":
            Wnd.Close(0);
            break;
    }
}

It doesn't change anything.
11-30-2006 03:39 PM
Profile E-Mail PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Countdown stops when close MSN
quote:
Originally posted by SnuZZer
Hi.
Like this?

code:
var gemDag;
var gemMaaned;
var gemAar;
var gemTimer;
var gemMinutter;
var gemBegivenhed;
var gemEfterBegivenhed;
var Status = "fra";

function OnEvent_SignIn(Email)
{
    Opdater();
}

Yes...

If you use a variable name in more then one function and you want it to be the same variable, like in you set it to something in function 1 and you read it back out in function 2, the variable must have a "global" scope/lifetime.

If you use a variable only in one function and thus not in any other function, it has a "local" scope/lifetime.

Each variable, no matter if it is global or local, must be declared first.
Global variables must be declared in global space, thus outside functions, while local variables must be defined in local space, thus inside functions...

quote:
Originally posted by SnuZZer
It doesn't change anything.
Because there are some more things wrong in your script though...

This post was edited on 12-01-2006 at 12:27 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
12-01-2006 12:25 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