Shoutbox

Delay a function - 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: Delay a function (/showthread.php?tid=64714)

Delay a function by Inuyasha on 08-09-2006 at 06:01 PM

Hello everybody :D

I've a question, which is:

Can someone make a function that delays another function for about 3 seconds?

And how do you make custom functions, so not the prefab functions, described in the Script Documentation, but a custom function like one does in Javascript.

I really need it, but i can't think of anything that really works.

Thx in advance.
Mike 8-|


RE: Delay a function by Spunky on 08-09-2006 at 08:49 PM

Try using the AddTimer function and OnTimer() event for the delay.

Custom functions? Do you mean like this?

code:
function myFunctionName(Param1,Param2){
...
...
...
}

To call the function:
code:
myFunctionName("Param1 Value","Param2 Value");


Hope this is what you wanted *-)
RE: Delay a function by Inuyasha on 08-10-2006 at 06:38 AM

Thx alot, i needed this :)


RE: Delay a function by leachy08 on 08-10-2006 at 07:29 AM

To add a timer you can use this code to start the timer:

code:
MsgPlus.AddTimer("atimername", 1000)

And then this code to find when the timer's time interval is reached.

code:
function OnEvent_Timer(TimerId) {
     if (TimerId == "atimername") {
          //Timer interval has been met.
     }
}


If you want to make the timer run just once then you can use:
MsgPlus.CancelTimer("atimerid") after you code in the OnEvent_Timer function above (Just after comment).

Alternatively if you want to make your program goto sleep using a Sleep() Sleep Function
But it will not let you use WLM whilst it is sleeping.
RE: Delay a function by Inuyasha on 08-10-2006 at 09:19 AM

Thx, but now i have this script:

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    MsgPlus.AddTimer("yoyo", 1000)
   
   
   
   
    if (Message == "=D")
    {
       
        ChatWnd.SendMessage(":')");
       
        function OnEvent_Timer(TimerId)
                {
                         if (TimerId == "yoyo")
                          {
                          ChatWnd.SendMessage("jeej");
                        //Timer interval has been met.
                         }
                }
       
    }
}   


But the timer won't work. I don't get it. :S
(Srry for tree, but the code tags filters tabs :P)
RE: Delay a function by RaceProUK on 08-10-2006 at 09:23 AM

Why have you put OnEvent_Timer() inside the other function? Put it outside.


RE: RE: Delay a function by Inuyasha on 08-10-2006 at 09:29 AM

quote:
Originally posted by RaceProUK
Why have you put OnEvent_Timer() inside the other function? Put it outside.

You mean like this? :
code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    MsgPlus.AddTimer("yoyo", 1000)
   
    function OnEvent_Timer(TimerId)
        {
                 if (TimerId == "yoyo")
                 {
                  ChatWnd.SendMessage("jeej");
                //Timer interval has been met.
                 }
        }
   
   
    if (Message == "=D")
    {
       
        ChatWnd.SendMessage(":')");
    }
}   


(Srry, but im yet a noob with this stuff :P)

This script won't work either.
RE: Delay a function by RaceProUK on 08-10-2006 at 09:32 AM

:|

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    MsgPlus.AddTimer("yoyo", 1000)
    if (Message == "=D") {
        ChatWnd.SendMessage(":')");
    }
}


function OnEvent_Timer(TimerId)
        {
    if (TimerId == "yoyo") {
        ChatWnd.SendMessage("jeej");
    }
        }


RE: RE: Delay a function by Inuyasha on 08-10-2006 at 09:39 AM

quote:
Originally posted by RaceProUK
:|

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    MsgPlus.AddTimer("yoyo", 1000)
    if (Message == "=D") {
        ChatWnd.SendMessage(":')");
    }
}


function OnEvent_Timer(TimerId)
        {
    if (TimerId == "yoyo") {
        ChatWnd.SendMessage("jeej");
    }
        }


Im getting an error which says "ChatWnd.SendMessage" is not defined....
RE: Delay a function by RaceProUK on 08-10-2006 at 09:43 AM

That's because there's no way at the moment for OnEvent_Timer() to know which chat window it's using.

All I did was move code around so functions were written properly.


RE: RE: Delay a function by Inuyasha on 08-10-2006 at 09:49 AM

quote:
Originally posted by RaceProUK
That's because there's no way at the moment for OnEvent_Timer() to know which chat window it's using.

All I did was move code around so functions were written properly.

Oke, allright. I get it now.
But no change to make it work properly? :x


Anyway, many thx to all :D