What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Debug needed] Delay Script

[Debug needed] Delay Script
Author: Message:
kjfk
New Member
*


Posts: 10
Joined: Jul 2006
O.P. [Debug needed] Delay Script
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.
07-07-2006 10:04 PM
Profile E-Mail PM Find Quote Report
Dhaya
Junior Member
**

Avatar
lala~

Posts: 25
Reputation: 4
38 / Male / –
Joined: Jul 2006
RE: [Debug needed] Delay Script
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

This post was edited on 07-07-2006 at 10:16 PM by Dhaya.
Godamn JScript ! I HATE you ! ... but I love you so much <3
07-07-2006 10:14 PM
Profile PM Find Quote Report
kjfk
New Member
*


Posts: 10
Joined: Jul 2006
O.P. RE: [Debug needed] Delay Script
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?

This post was edited on 07-07-2006 at 10:53 PM by kjfk.
07-07-2006 10:29 PM
Profile E-Mail PM Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: [Debug needed] Delay Script
Err, save the window in the variable...

WndRepeat = ChatWnd;

Place that after:
    strMessage = arrayMessage[2];
07-07-2006 10:57 PM
Profile E-Mail PM Find Quote Report
kjfk
New Member
*


Posts: 10
Joined: Jul 2006
O.P. RE: [Debug needed] Delay Script
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
07-07-2006 11:03 PM
Profile E-Mail PM Find Quote Report
kjfk
New Member
*


Posts: 10
Joined: Jul 2006
O.P. RE: [Debug needed] Delay Script
Someone? Please.
Sry for bump, but my last post was long ago :$
07-12-2006 08:31 AM
Profile E-Mail PM Find Quote Report
mickael9
Full Member
***


Posts: 117
Reputation: 3
33 / Male / Flag
Joined: Jul 2005
RE: [Debug needed] Delay Script
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)
07-12-2006 10:42 AM
Profile PM Web Find Quote Report
kjfk
New Member
*


Posts: 10
Joined: Jul 2006
O.P. RE: [Debug needed] Delay Script
thank you, works nice ^^
07-12-2006 11:12 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