Shoutbox

Countdown stops when close MSN - 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: Countdown stops when close MSN (/showthread.php?tid=68990)

Countdown stops when close MSN by SnuZZer on 11-30-2006 at 06:48 AM

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
RE: Countdown stops when close MSN by NiteMare on 11-30-2006 at 06:58 AM

you do know there are several other scripts that do this already... such as mine [Release] CountDown [Update: Version 2.9.0]


RE: RE: Countdown stops when close MSN by CookieRevised on 11-30-2006 at 08:15 AM

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...
RE: Countdown stops when close MSN by SnuZZer on 11-30-2006 at 01:52 PM

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.


RE: Countdown stops when close MSN by Spunky on 11-30-2006 at 02:13 PM

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(){{
...
...
}

RE: Countdown stops when close MSN by SnuZZer on 11-30-2006 at 03:39 PM

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.
RE: Countdown stops when close MSN by CookieRevised on 12-01-2006 at 12:25 AM

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...