Shoutbox

[Error] 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: [Error] AddTimer (/showthread.php?tid=78927)

[Error] AddTimer by Luca on 11-10-2007 at 08:14 PM

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?
RE: [Error] AddTimer by vikke on 11-10-2007 at 08:26 PM

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.
RE: [Error] AddTimer by Luca on 11-10-2007 at 09:04 PM

I did the change but i don't resolve the problem...how can i send all my emoticons?


RE: [Error] AddTimer by Huhu_Manix on 11-10-2007 at 10:58 PM

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. ;)
RE: RE: [Error] AddTimer by vikke on 11-10-2007 at 11:49 PM

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. :)
RE: [Error] AddTimer by Luca on 11-11-2007 at 10:34 AM

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