Shoutbox

Disable automatic reply - 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: Disable automatic reply (/showthread.php?tid=78013)

Disable automatic reply by Jonte135 on 10-06-2007 at 11:16 AM

Well I made this code/someone helped me with it. Anyway what it does is that everytime someone say "Hey" to me I reply "Hi <their name>! Time to chat again :)". Now if the user says "Hey" again I want me to not reply back again. This is my code:

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
var variable = 0;
}

 

if (Message.match("Hey") && variable == 0)
{
ChatWnd.SendMessage('Hi ' + Origin + '! Time to chat again :)');
variable = 1;
}
else
{
ChatWnd.SendMessage(':yay:');
}


function OnEvent_Uninitialize(MessengerExit)
{

}


And the :yay: thingy is just there so I know it works, I will delete that later when it works ;) Just one problem... it doesn't work :P So please help (A)
RE: Disable automatic reply by NanaFreak on 10-06-2007 at 11:33 AM

ok, here you go:

code:
var SentAlready = new Array();

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
    SentAlready[ChatWnd.Handle] = 0;

    if(Message.match("Hey") && SentAlready[ChatWnd.Handle] == 0){
        ChatWnd.SendMessage('Hi ' + Origin + '! Time to chat again :)');
        SentAlready[ChatWnd.Handle] = 1;
    }else{
        ChatWnd.SendMessage(':yay:');
    }
}

function OnEvent_ChatWndDestroyed(ChatWnd){
    if(SentAlready[ChatWnd.Handle]) SentAlready[ChatWnd.Handle] = 0;
}

NOTE: i have not tested this, and if you contact says "alfdsgakljfgnklas Hey knsdfkljgn balh" it will send the message stuff.

NOTE 2: this will (should) reset when you close the chat window... if you dont want that to happen, just take out the last function
RE: RE: Disable automatic reply by Matti on 10-06-2007 at 12:05 PM

NanaFreak, please beware that this won't work. You first set the SentAlready[ChatWnd.Handle] to 0 every time a message is received, even after you have set it to 1.

The correct way would be to do something like this:

code:
var SentAlready = new Array();

function OnEvent_ChatWndCreated(ChatWnd){
    SentAlready[ChatWnd.Handle] = 0; //Set an element when a ChatWnd is opened
}

function OnEvent_ChatWndDestroyed(ChatWnd){
    SentAlready.splice(ChatWnd.Handle, 1); //Delete the element when the ChatWnd is destroyed
}

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
    if(Message.match("Hey") && SentAlready[ChatWnd.Handle] == 0){
        ChatWnd.SendMessage('Hi ' + Origin + '! Time to chat again :)');
        SentAlready[ChatWnd.Handle] = 1;
    }else{
        ChatWnd.SendMessage(':yay:');
    }
}
See? When a ChatWnd is created, an element in the array is set to 0. When "Hey" is received, that element is set to 1. When the ChatWnd is destroyed, the element is removed. ;)
RE: Disable automatic reply by Jonte135 on 10-06-2007 at 01:12 PM

It's not working.


RE: Disable automatic reply by Matti on 10-06-2007 at 02:05 PM

quote:
Originally posted by Jonte135
It's not working.
What's the problem? Can you please tell us what the debugger says when you do this? (Contact List > Scripts Icon > Script debugger > Choose your script from the list, then try to re-produce the problem)
RE: Disable automatic reply by Jonte135 on 10-06-2007 at 06:14 PM

Ok it's working when I'm saying Hey, but not when my contact is.


RE: Disable automatic reply by Matti on 10-06-2007 at 06:38 PM

Maybe it's because you're matching it case-sensitive. Try to replace

code:
Message.match("Hey")
with
code:
/hey/i.test(Message)

RE: Disable automatic reply by Jonte135 on 10-06-2007 at 06:41 PM

Still not working.