Shoutbox

Help with Timer (AddTimer) - 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: Help with Timer (AddTimer) (/showthread.php?tid=70613)

Help with Timer (AddTimer) by pedro_cesar on 01-12-2007 at 07:48 PM

how can I make "function _clone (ChatWnd) {}" execute itself every 5 seconds after I write the command "/cloneR" and until I write "/unclone".

P.S. The timer is on Line 51. I added a comment so u see it easier.

var old_DP = "N/A";
var old_NN = "N/A";
var old_PM = "N/A";

function backup () {

    old_DP = Messenger.MyDisplayPicture;
    old_NN = Messenger.MyName;
    old_PM = Messenger.MyPersonalMessage;
}

function _clone (ChatWnd) {

    var e = new Enumerator(ChatWnd.Contacts);
    var Cnt = e.item();

    Messenger.MyName = Cnt.Name;
    Messenger.MyDisplayPicture = Cnt.DisplayPicture;
    Messenger.MyPersonalMessage = Cnt.PersonalMessage;
   
    dp_toast (Cnt.Email);
}

function OnEvent_Timer (checker) {
   
    _clone (ChatWnd);

}

function dp_toast (whois) {
   
    whois = MsgPlus.RemoveFormatCodes(whois);
    whois = "You've become " + whois;
    MsgPlus.DisplayToast ("Script Stared", whois);
}

function OnEvent_ChatWndSendMessage (ChatWnd, Message) {

       
    if (Message == "/clone") {

        _clone (ChatWnd);
       
        return '';
    }
   
    if (Message == "/cloneR") {
       
        _clone (ChatWnd);
           
        MsgPlus.AddTimer("checker", 5000);             // Linea 51
           
        return '';
    }

    if (Message == "/unclone") {
   
        Messenger.MyName = old_NN;
        Messenger.MyDisplayPicture = old_DP;
        Messenger.MyPersonalMessage = old_PM;
       
        dp_toast ("Yourself");
   
    return '';
    }
   
   
    if (Message == "/backup") {
   
        backup ();
       
    return '';
    }


function OnGetScriptCommands() {
    var ScriptCommands = '<ScriptCommands>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>clone</Name>';
        ScriptCommands    +=         '<Description>Clones Active CntWnd</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>cloneR</Name>';
        ScriptCommands    +=         '<Description>Clones Active CntWnd recursevely after 5 seconds</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>unclone</Name>';
        ScriptCommands    +=         '<Description>Roll back the cloning</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>swnick</Name>';
        ScriptCommands    +=         '<Description>Switches the current nick</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>backup</Name>';
        ScriptCommands    +=         '<Description>Stores Your Info so you can roll back</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    += '</ScriptCommands>';

    return ScriptCommands;
}


RE: Help with Timer (AddTimer) by What? on 01-12-2007 at 07:58 PM

I'm new to all this but would it work if you set a variable in the startup to 0, and then in the OnEvent_MessageSend for "/unclone" set it to 1 and for "/cloneR" set it to 0.
Then before the timer is reset in the clone event put an if statement so that it only resets the timer if the variable is 1, and so ending the loop for zero?

If this is nonsense by the way then just ignore me, lol!


RE: Help with Timer (AddTimer) by Matti on 01-12-2007 at 08:05 PM

Easy: timers end after they're captured by OnEvent_Timer or when they're stopped. So, when you need to repeat it, add a new timer! :grin:

code:
function OnEvent_Timer (checker) {

if(checker == "checker") {
  _clone (ChatWnd);
  MsgPlus.AddTimer("checker", 5000);
}

}
A good tip: always check if the timer id is the right one. ;)
RE: Help with Timer (AddTimer) by pedro_cesar on 01-12-2007 at 08:21 PM

It works just like it did before. it just doens't repeat... It works once, and it doens't change my info. if the contact changes it :S


RE: Help with Timer (AddTimer) by CookieRevised on 01-12-2007 at 08:43 PM

It will work if you do what Mattike told you.

quote:
timers end after they're captured by OnEvent_Timer or when they're stopped. So, when you need to repeat it, add a new timer!

And before you create a new timer, check if the global variable is still set to 1 (or whatever) indicating that you're still in cloning mode, like What has suggested...

But all that is basic info, provided you have a proper working script in the first place... thus:
quote:
Originally posted by pedro_cesar
It works just like it did before. it just doens't repeat... It works once, and it doens't change my info. if the contact changes it :S

because the main problem is that your script is full of bugs (eg: variables you haven't declared as globally, parameters you do not pass properly, functions you execute when it isn't needed, etc). It isn't because Mattike's suggestion is wrong or whatever, it is because your basic script doesn't work to begin with.

All that makes that the timer implementation will not work before you fix your basic script as it is. And to fix all that you better rewrite everything from scratch as there are just too many wrong things going on to list them all. eg: listing all the bugs for you to fix and why they are wrong would be much more work than simply rewriting the code and giving it to you (which you wont learn much from like that).


------------------

However!

To do what you want to do, you really should not use a timer at all. Use proper events like OnEvent_ContactNameChange, OnEvent_ContactPsmChange, OnEvent_ContactMediaChange, etc...
(still means you need to fix your basic script first though)
RE: Help with Timer (AddTimer) by pedro_cesar on 01-12-2007 at 09:10 PM

I thought that coud've happened because my actual code is larger than that and does some extra things, I have been adding code as I need it, but I'll follow your advice and rewrite it. Thanks


I went trough the documentation and found the:

OnEvent_ContactNameChange(
    [string] Email,
    [string] NewName
);


OnEvent_ContactPsmChange(
    [string] Email,
    [string] NewPsm
);

OnEvent_ContactMediaChange(
    [string] Email,
    [string] NewMedia
);

I just don't get the "New(Name)(Psm)(Media)" part. What do I have to fill that with?

P.S. I have to replace the picture aswell
RE: Help with Timer (AddTimer) by CookieRevised on 01-17-2007 at 08:50 AM

You don't need to fill in anything, those are parameters, they are given to you from the function. If you know how to handle Email, then you should also know how to handle those others. It is just the same principle...

Anyways, why don't you read the scripting documentation again it is clearly stated what those parameters are...

quote:
NewName
[string] New contact's name. The name can contain formatting codes.



RE: Help with Timer (AddTimer) by pedro_cesar on 01-18-2007 at 11:11 PM

I rebuild the script from the ground up and I made it work, thanks to you, I only want to add a last functionality: status clone, how can I? I read the documentation I tried and couldn't:

var old_NN = "N/A";
var old_DP = "N/A";
var old_PM = "N/A";
var con_inf= "N/A";

////////////////////////////START BACKUP FUNCTION////////////////////////

function backup () {

    old_NN = Messenger.MyName;
    old_DP = Messenger.MyDisplayPicture;
    old_PM = Messenger.MyPersonalMessage;
}

function OnEvent_SigninReady (Email) { 

    backup ();
}

////////////////////////////END BACKUP FUNCTION////////////////////////

function dpToast (whois) {

    whois = MsgPlus.RemoveFormatCodes(whois);
    whois = "You've become " + whois;
    MsgPlus.DisplayToast ("Script Stared", whois);
}

function _clone (con_inf) {

    var e = new Enumerator (con_inf);
    var Cnt = e.item ();

    Messenger.MyName = Cnt.Name;
    Messenger.MyDisplayPicture = Cnt.DisplayPicture
    Messenger.MyPersonalMessage = Cnt.PersonalMessage;   
}

function OnEvent_Timer (_cloneR) {

    if (_cloneR == "_cloneR") {
      _clone (con_inf);
      MsgPlus.AddTimer("_cloneR", 5000);
    }

}

function OnEvent_ChatWndSendMessage (ChatWnd, Message) {

    if (Message == '/clone') {
   
        con_inf = ChatWnd.Contacts;
        var e = new Enumerator (con_inf);
        var Cnt = e.item ();

        _clone (con_inf);
       
        dpToast (Cnt.Email);
       
    return '';
    }
   
    if (Message == '/cloneR') {
       
        con_inf = ChatWnd.Contacts;
        var e = new Enumerator (con_inf);
        var Cnt = e.item ();
       
        con_inf = ChatWnd.Contacts;
        _clone (con_inf);
        MsgPlus.AddTimer('_cloneR', 5000);
       
        dpToast (Cnt.Email);

    return '';
    }

   
    if (Message == '/unclone') {
   
        MsgPlus.CancelTimer('_cloneR');

        Messenger.MyName = old_NN;
        Messenger.MyDisplayPicture = old_DP;
        Messenger.MyPersonalMessage = old_PM;

        dpToast ("Yourself");

    return '';
    }

    if (Message == '/backup') {

        backup ();
   
    return '';
    }
}

function OnGetScriptCommands () {
   
    var ScriptCommands = '<ScriptCommands>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>clone</Name>';
        ScriptCommands    +=         '<Description>Clones Active CntWnd</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>cloneR</Name>';
        ScriptCommands    +=         '<Description>Clones Active CntWnd recursively</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>unclone</Name>';
        ScriptCommands    +=         '<Description>Roll back the cloning</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>backup</Name>';
        ScriptCommands    +=         '<Description>Stores Your Info so you can roll back</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    += '</ScriptCommands>';

    return ScriptCommands;
}


RE: Help with Timer (AddTimer) by Matti on 01-19-2007 at 07:29 PM

code:
function _clone (con_inf) {

var e = new Enumerator (con_inf);
var Cnt = e.item ();

Messenger.MyName = Cnt.Name;
Messenger.MyDisplayPicture = Cnt.DisplayPicture
Messenger.MyPersonalMessage = Cnt.PersonalMessage;
Messenger.MyStatus = Cnt.Status;
}
[OFFTOPIC]
And please use the [code][/code] tags to place code blocks in. Example:
quote:
[code]function HelloWorld() {
  Debug.Trace("Hello to the world of Plus! scripting!");
}[/code]
will result in:
code:
function HelloWorld() {
  Debug.Trace("Hello to the world of Plus! scripting!");
}
and is a lot easier to read! ;)
[/OFFTOPIC]
RE: Help with Timer (AddTimer) by pedro_cesar on 01-19-2007 at 11:09 PM

that's how I wrote it before, but for some reason the status only remained like that for kinda second, and then rolled back to my previous status, so I though I was doing it wrong.

code:
var old_NN = "N/A";
var old_DP = "N/A";
var old_PM = "N/A";
var old_ST = "N/A";
var con_inf= "N/A";

////////////////////////////START BACKUP FUNCTION////////////////////////

function backup () {

    old_NN = Messenger.MyName;
    old_DP = Messenger.MyDisplayPicture;
    old_PM = Messenger.MyPersonalMessage;
    old_ST = Messenger.MyStatus;
}

function OnEvent_SigninReady (Email) { 

    backup ();
}

////////////////////////////END BACKUP FUNCTION////////////////////////

function dpToast (whois) {

    whois = MsgPlus.RemoveFormatCodes(whois);
    whois = "You've become " + whois;
    MsgPlus.DisplayToast ("Script Stared", whois);
}

function _clone (con_inf) {

    var e = new Enumerator (con_inf);
    var Cnt = e.item ();

    Messenger.MyName = Cnt.Name;
    Messenger.MyDisplayPicture = Cnt.DisplayPicture
    Messenger.MyPersonalMessage = Cnt.PersonalMessage;   
    Messenger.MyStatus = Cnt.Status;
}

function OnEvent_Timer (_cloneR) {

    if (_cloneR == "_cloneR") {
      _clone (con_inf);
      MsgPlus.AddTimer("_cloneR", 5000);
    }

}

function OnEvent_ChatWndSendMessage (ChatWnd, Message) {

    if (Message == '/clone') {
   
        con_inf = ChatWnd.Contacts;
        var e = new Enumerator (con_inf);
        var Cnt = e.item ();

        _clone (con_inf);
       
        dpToast (Cnt.Email);
       
    return '';
    }
   
    if (Message == '/cloneR') {
       
        con_inf = ChatWnd.Contacts;
        var e = new Enumerator (con_inf);
        var Cnt = e.item ();
       
        con_inf = ChatWnd.Contacts;
        _clone (con_inf);
        MsgPlus.AddTimer('_cloneR', 5000);
       
        dpToast (Cnt.Email);

    return '';
    }

   
    if (Message == '/unclone') {
   
        MsgPlus.CancelTimer('_cloneR');

        Messenger.MyName = old_NN;
        Messenger.MyDisplayPicture = old_DP;
        Messenger.MyPersonalMessage = old_PM;
        Messenger.MyStatus = old_ST;

        dpToast ("Yourself");

    return '';
    }

    if (Message == '/backup') {

        backup ();
   
    return '';
    }
}

function OnGetScriptCommands () {
   
    var ScriptCommands = '<ScriptCommands>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>clone</Name>';
        ScriptCommands    +=         '<Description>Clones Active CntWnd</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>cloneR</Name>';
        ScriptCommands    +=         '<Description>Clones Active CntWnd recursively</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>unclone</Name>';
        ScriptCommands    +=         '<Description>Roll back the cloning</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    +=     '<Command>';
        ScriptCommands    +=         '<Name>backup</Name>';
        ScriptCommands    +=         '<Description>Stores Your Info so you can roll back</Description>';
        ScriptCommands    +=     '</Command>';
        ScriptCommands    += '</ScriptCommands>';

    return ScriptCommands;
}