Shoutbox

[Debug needed] Delay Script - 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: [Debug needed] Delay Script (/showthread.php?tid=62780)

[Debug needed] Delay Script by kjfk on 07-07-2006 at 10:04 PM

I am on a learning phase of scripting, so I figured that i should try making a Delay command.
This is what i got

code:
function OnEvent_ChatWndSendMessage(ChatWnd, sMessage)
{
        var stringMessage = sMessage;
        var arrayMessage = stringMessage.split(";");

        var stringCommand = arrayMessage[0];
        var variableDelay = arrayMessage[1];
        var stringSendMessage = arrayMessage[2];

        if (stringCommand == "#Delay")
        {
                MsgPlus.AddTimer("timerDelay",variableDelay);
                OnEvent_Timer("timerDelay")
                {
                        return stringSendMessage;
                }
        }
        else return sMessage
}



Something is wrong since all that happens when i type "#Delay;1000;1 second delay" is that i just send excactly that message. The outcome i want is that only the last part, "1 second delay" should be sent, and 1 second after i type the delay command.
So... What is wrong? How to correct it?
Help me please.
RE: [Debug needed] Delay Script by Dhaya on 07-07-2006 at 10:14 PM

first, you'll have to place the OnEvent_Timer() function out of this condition and out of this function.

then, you should do some verifications before your operations. for example if you don't type something with the right format (which is blabla;blabla;blabla) the script will trigger errors when you send Messages.

try this

code:
var WndRepeat = new ChatWnd(); // used to store the ChatWnd
var strMessage = "";
function OnEvent_ChatWndSendMessage(ChatWnd, sMessage)
{
  if (sMessage.match(/^#.+;.+;.+/)
  {
    var arrayMessage = sMessage.split(";");

    var stringCommand = arrayMessage[0];
    var variableDelay = arrayMessage[1];
    strMessage = arrayMessage[2];

    if (stringCommand == "#Delay")
    {

      MsgPlus.AddTimer("timerDelay",variableDelay);
      return "";
    }
  }
}

function OnEvent_Timer(TimerId)
{
  if (TimerId == "timerDelay") WndRepeat.SendMessage(strMessage);
}


well, i'm not sure about the regular expression and i'm too lazy to test it. Test and modify this thing if needed :p
RE: [Debug needed] Delay Script by kjfk on 07-07-2006 at 10:29 PM

i changed the "if (sMessage.match(/^#.+;.+;.+/)"
to "if (sMessage.match(/^#.+;.+;.+/))" //(what does all those signs mean btw?)
also changed "strMessage = arrayMessage[2];"
to "var strMessage = arrayMessage[2];"
in Dhaya's code

but.. it doesnt send anything now ^^
i think all the variables are right.. soo.. what is wrong now?


RE: [Debug needed] Delay Script by J-Thread on 07-07-2006 at 10:57 PM

Err, save the window in the variable...

WndRepeat = ChatWnd;

Place that after:
    strMessage = arrayMessage[2];


RE: [Debug needed] Delay Script by kjfk on 07-07-2006 at 11:03 PM

What i have now...

code:
var WndRepeat = new ChatWnd(); // used to store the ChatWnd
var strMessage = "";
function OnEvent_ChatWndSendMessage(ChatWnd, sMessage)
{
if (sMessage.match(/^#.+;.+;.+/))
{
var arrayMessage = sMessage.split(";");

var stringCommand = arrayMessage[0];
var variableDelay = arrayMessage[1];
strMessage = arrayMessage[2];

WndRepeat = ChatWnd;

if (stringCommand == "#Delay")
{

MsgPlus.AddTimer("timerDelay",variableDelay);
return "";
}
}
}

function OnEvent_Timer(TimerId)
{
if (TimerId == "timerDelay") WndRepeat.SendMessage(strMessage);
}



the outcome when i type "#Delay;2000;2 sec delay":
the messenger sends "#Delay;2000;2 sec delay"

^o)

also tried doing "var strMessage = arrayMessage[2];" since im new and dont really know if it should be with or without "var".. but it is the same outcome
RE: [Debug needed] Delay Script by kjfk on 07-12-2006 at 08:31 AM

Someone? Please.
Sry for bump, but my last post was long ago :$


RE: [Debug needed] Delay Script by mickael9 on 07-12-2006 at 10:42 AM

code:
var TimerParams  = {};

function OnEvent_ChatWndSendMessage(ChatWnd, sMessage)
{
     var regex = /^#Delay;\s?([0-9]+);\s?(.+)$/;
     var match = regex.exec(sMessage);
     if (match)
     {
          var nDelay     = match[1];
          var sMessage   = match[2];
         
          var sTimerName = "timerDelay_" + Math.random().toString().replace(/[^0-9]/,'');
          TimerParams[sTimerName] = {"sMessage" : sMessage, "ChatWnd" : ChatWnd};
         
          MsgPlus.AddTimer(sTimerName,nDelay);
         
          return "";
     }
}

function OnEvent_Timer(TimerId)
{
     if (TimerId.indexOf("timerDelay_") == 0)
     {
          var sMessage = TimerParams[TimerId].sMessage;
          var ChatWnd  = TimerParams[TimerId].ChatWnd;
         
          ChatWnd.SendMessage(sMessage);         
         
          delete(TimerParams[TimerId]);
     }
}

works fine for me (H)
RE: [Debug needed] Delay Script by kjfk on 07-12-2006 at 11:12 AM

thank you, works nice ^^