What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Help with Timer (AddTimer)

Help with Timer (AddTimer)
Author: Message:
pedro_cesar
Junior Member
**

Avatar

Posts: 61
36 / Male / –
Joined: Dec 2006
Status: Away
O.P. Help with Timer (AddTimer)
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;
}
01-12-2007 07:48 PM
Profile E-Mail PM Web Find Quote Report
What?
New Member
*


Posts: 4
Joined: Jan 2007
RE: Help with Timer (AddTimer)
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!

This post was edited on 01-12-2007 at 08:00 PM by What?.
01-12-2007 07:58 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Help with Timer (AddTimer)
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. ;)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
01-12-2007 08:05 PM
Profile E-Mail PM Web Find Quote Report
pedro_cesar
Junior Member
**

Avatar

Posts: 61
36 / Male / –
Joined: Dec 2006
Status: Away
O.P. RE: Help with Timer (AddTimer)
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
01-12-2007 08:21 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: Help with Timer (AddTimer)
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)

This post was edited on 01-12-2007 at 08:51 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-12-2007 08:43 PM
Profile PM Find Quote Report
pedro_cesar
Junior Member
**

Avatar

Posts: 61
36 / Male / –
Joined: Dec 2006
Status: Away
O.P. RE: Help with Timer (AddTimer)
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
01-12-2007 09:10 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: Help with Timer (AddTimer)
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.



This post was edited on 01-17-2007 at 08:52 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-17-2007 08:50 AM
Profile PM Find Quote Report
pedro_cesar
Junior Member
**

Avatar

Posts: 61
36 / Male / –
Joined: Dec 2006
Status: Away
O.P. RE: Help with Timer (AddTimer)
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;
}

This post was edited on 01-19-2007 at 02:06 AM by pedro_cesar.
01-18-2007 11:11 PM
Profile E-Mail PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Help with Timer (AddTimer)
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]
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
01-19-2007 07:29 PM
Profile E-Mail PM Web Find Quote Report
pedro_cesar
Junior Member
**

Avatar

Posts: 61
36 / Male / –
Joined: Dec 2006
Status: Away
O.P. RE: Help with Timer (AddTimer)
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;
}


This post was edited on 01-19-2007 at 11:10 PM by pedro_cesar.
01-19-2007 11:09 PM
Profile E-Mail PM Web 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