What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Error] AddTimer

[Error] AddTimer
Author: Message:
Luca
New Member
*


Posts: 11
34 / Male / Flag
Joined: Nov 2007
O.P. [Error] AddTimer
Hi boys... :D
Excuse me for my english but I am italian and so I don't speak very well...
I have a problem with the AddTimer function...I realized a script that send all my emoticons to a contact when i write "invia_emoticons"...I send the emoticons one at a time because the limit for a message is 5 emoticons...
when i send the emoticons,only some emoticons was send..In my opinion this problem is caused by the different of the speed between the processing of the data and processing of the send of data..
OK...so i think to add the AddTimer between a send and other...
But i see that this function isn't execute...
the code of the function is:
code:
function send_emoticon(wnd)
{
       
       var smile="";
       var Emoticons = Messenger.CustomEmoticons;
       var e = new Enumerator(Emoticons);
       var Emoticon;
       if(wnd.EditChangeAllowed==true)
       {
               for(; !e.atEnd(); e.moveNext())
               {
                       MsgPlus.AddTimer("timer",5000);
                       Emoticon = e.item();
                       smile=" "+Emoticon.Shortcut;
                       Debug.Trace(smile);
                       wnd.SendMessage(smile);
               }
       }
}

function onEvent_Timer(timer)
{
}

the output of the debug is:
code:
):)
Funzione chiamata: OnEvent_ChatWndSendMessage
-_-1
Funzione chiamata: OnEvent_ChatWndSendMessage
-_^
Funzione chiamata: OnEvent_ChatWndSendMessage
.muha.
Funzione chiamata: OnEvent_ChatWndSendMessage
2CRY
Funzione chiamata: OnEvent_ChatWndSendMessage
2MALE
Funzione chiamata: OnEvent_ChatWndSendMessage
2O_O
Funzione chiamata: OnEvent_ChatWndSendMessage
2SBAVAA
Funzione chiamata: OnEvent_ChatWndSendMessage
3@:
Funzione chiamata: OnEvent_ChatWndSendMessage
3O_O
Funzione chiamata: OnEvent_ChatWndSendMessage
:L
Funzione chiamata: OnEvent_ChatWndSendMessage
;D
Funzione chiamata: OnEvent_ChatWndSendMessage
@:
Funzione chiamata: OnEvent_ChatWndSendMessage
ADDIO
Funzione chiamata: OnEvent_ChatWndSendMessage
ADORE
Funzione chiamata: OnEvent_ChatWndSendMessage
AFFRANT
Funzione chiamata: OnEvent_ChatWndSendMessage
AMMONIT
ANNOIO
ARGHARG

you can see that only the first emoticons are print...Why there isn't in the output of the debug Funzione chiamata: OnEvent_Timer...why don't the timer stop for 5 second the excute of the program?
11-10-2007 08:14 PM
Profile E-Mail PM Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
Joined: May 2006
RE: [Error] AddTimer
Try changing:
code:
function onEvent_Timer(timer)
to:
code:
function OnEvent_Timer(timer)
It's getting called five seconds after you sent the first smiley to your contact, perhaps you didn't wait that long.

If you want it to wait 5 seconds before sending each smiley, you can either use Sleep (would freeze Messenger), or you can send the smiley inside the OnEvent_Timer function.
11-10-2007 08:26 PM
Profile E-Mail PM Find Quote Report
Luca
New Member
*


Posts: 11
34 / Male / Flag
Joined: Nov 2007
O.P. RE: [Error] AddTimer
I did the change but i don't resolve the problem...how can i send all my emoticons?
11-10-2007 09:04 PM
Profile E-Mail PM Find Quote Report
Huhu_Manix
Full Member
***

Avatar
Upload me again... *salivate*

Posts: 106
– / Male / –
Joined: Jul 2006
RE: [Error] AddTimer
You use "MsgPlus.AddTimer("timer",5000);" like a sleeper which stops the loop for 5 seconds. BUT the msgplus's timer is a timer which calls the function "OnEvent_Timer()" when it finish.

So you've to use it like this :

code:
var the_wnd;
var Emoticons;
var e;

function send_emoticon(wnd)
{
       if(wnd.EditChangeAllowed==true)
       {
           Emoticons = Messenger.CustomEmoticons;
           e = new Enumerator(Emoticons);
               the_wnd = wnd;  // Stock the chat window
           OnEvent_Timer("timer_name"); // launch the timer's loop
       }
}

function OnEvent_Timer(timer)
{
    if(timer == "timer_name"){
        var smile="";
        for(var i = 0; !e.atEnd()&&i<5; e.moveNext(), i++)smile=" "+e.item().Shortcut;
            the_wnd.SendMessage(smile); // Send the 5 smilies
            Debug.Trace(smile);
            if(!e.atEnd())MsgPlus.AddTimer("timer_name", 5000); // If not finished yet, recall the function in 5 seconds
    }
}

Hope you understand !

EDIT : Not tried but should works, otherwise it's enough to help you about your project i think. ;)

This post was edited on 11-10-2007 at 11:00 PM by Huhu_Manix.
11-10-2007 10:58 PM
Profile E-Mail PM Web Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
Joined: May 2006
RE: RE: [Error] AddTimer
I was going to recommend something like this, but then I thought what if there are 2 windows opened at the same time? :)
Solution: You can set the TimerID to ChatWnd, that way, you get one timer for each conversation. Then you also have to separate the "e" variable using an array.

For instance:
code:
var Emoticons;
var e = new Array();
var wnds = new Array();

function send_emoticon(wnd)
{
       if(wnd.EditChangeAllowed==true)
       {
           Emoticons = Messenger.CustomEmoticons;
           e[""+ wnd.Handle] = new Enumerator(Emoticons);
               wnds[""+ wnd.Handle] = wnd; // Stock the chat window
           OnEvent_Timer(""+ wnd.Handle); // launch the timer's loop
       }
}
function OnEvent_Timer(timer)
{
    if(wnds[timer].EditChangeAllowed==true){
        var smile="";
        for(var i = 0; !e[timer].atEnd()&&i<5; e.moveNext(), i++)smile=" "+e[timer].item().Shortcut;
            wnds[timer].SendMessage(smile); // Send the 5 smilies
            Debug.Trace(smile);
            if(!e.atEnd())MsgPlus.AddTimer("timer_name", 5000); // If not finished yet, recall the function in 5 seconds
    }
}


I haven't tried this code, I will do tomorrow. :)
11-10-2007 11:49 PM
Profile E-Mail PM Find Quote Report
Luca
New Member
*


Posts: 11
34 / Male / Flag
Joined: Nov 2007
O.P. RE: [Error] AddTimer
Great...the script works...:D
Thank Huhu_Manix and vikke...I solve the problem in this way,naturally with your help...
code:
function send_emoticon(wnd)
{
    if(wnd.EditChangeAllowed==true)
     {
         Emoticons = Messenger.CustomEmoticons;
         e = new Enumerator(Emoticons);
         the_wnd = wnd;  // copia l'oggetto finestra
         OnEvent_Timer("timer_name"); // lancia il ciclo
     }
}

function OnEvent_Timer(timer)
{
    if(timer == "timer_name")
    {
        var smile="";
        for(var i = 0; !e.atEnd()&&i<5; e.moveNext(), i++)smile=smile+" "+e.item().Shortcut;
         the_wnd.SendMessage(smile); // invia 5 smilies per volta
         Debug.Trace(smile);
            if(!e.atEnd())MsgPlus.AddTimer("timer_name", 4000); // chiama nuovamente l'evento Timer
    }
}

I highlighted your only forgetfulness...

I hope to learn more in this forum...:D
11-11-2007 10:34 AM
Profile E-Mail 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