[Help] ChatWndReceiveMessage function |
Author: |
Message: |
SquidWeed
New Member
Posts: 5
Joined: Jan 2009
|
O.P. [Help] ChatWndReceiveMessage function
Hello,
I'm new to scripting in msgPlus.
I made a script that sends a message as soon as it recieves one.
for some reason, after a random amount of messages recieved, ChatWndReceiveMessage function stops responding.
It start responding again only when the next message is recieved.
I would like to know why it stops responding, and how can I stop this from happening?
tnx in advance,
SquidWeed
|
|
01-28-2009 10:52 PM |
|
|
djdannyp
Elite Member
Danny <3 Sarah
Posts: 3546 Reputation: 31
38 / /
Joined: Mar 2006
|
RE: [Help] ChatWndReceiveMessage function
Can you post your code?
|
|
01-28-2009 11:04 PM |
|
|
SquidWeed
New Member
Posts: 5
Joined: Jan 2009
|
O.P. RE: [Help] ChatWndReceiveMessage function
function OnEvent_Initialize(MessengerStart)
{
activated=false;
contact=null;
msgs=new Array("bb","cya","have fun","good night");
}
function OnEvent_ChatWndSendMessage(ChatWnd,Message){
if(Message == "*bye*"){
activated=!activated;
var e = new Enumerator(ChatWnd.Contacts);
contact=e.item();
}
}
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){
if(activated && contact.Name==Origin) ChatWnd.SendMessage(msgs[Math.ceil(Math.random()*msgs.length)]);
}
|
|
01-28-2009 11:15 PM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: [Help] ChatWndReceiveMessage function
Messenger Plus! Live has a built-in flood protection on the ChatWnd.SendMessage function, which prevents a script from sending lots and lots of messages - I think the limit was 10 or 15 or so. I guess that's what you've encountered here, and there's nothing you can do to make it send more. Perhaps you could add a delay of 1 or 2 seconds in your ReceiveMessage event with MsgPlus.AddTimer and OnEvent_Timer to somehow work around this problem, although I'm not very sure whether it'll stop the flood protection.
|
|
01-29-2009 04:50 PM |
|
|
Spunky
Former Super Mod
Posts: 3658 Reputation: 61
36 / /
Joined: Aug 2006
|
RE: [Help] ChatWndReceiveMessage function
quote: Originally posted by Matti
Messenger Plus! Live has a built-in flood protection on the ChatWnd.SendMessage function, which prevents a script from sending lots and lots of messages - I think the limit was 10 or 15 or so. I guess that's what you've encountered here, and there's nothing you can do to make it send more. Perhaps you could add a delay of 1 or 2 seconds in your ReceiveMessage event with MsgPlus.AddTimer and OnEvent_Timer to somehow work around this problem, although I'm not very sure whether it'll stop the flood protection.
IIRC flood protection is at 15 messages at which point the user needs to send a message for it to be reset
<Eljay> "Problems encountered: shit blew up"
|
|
01-29-2009 06:31 PM |
|
|
SquidWeed
New Member
Posts: 5
Joined: Jan 2009
|
O.P. RE: [Help] ChatWndReceiveMessage function
I already tried to add a delay of 2 seconds, it didn't work.
And I'm not sure it's a flood protection, because It never gets to 15 messages, the number of messages sent is between 3 to 12.
Besides that, I'm sending only one message at the time so basically it's not flooding, it's an auto-respond
tnx for your replies!
|
|
01-30-2009 02:44 AM |
|
|
SquidWeed
New Member
Posts: 5
Joined: Jan 2009
|
O.P. RE: [Help] ChatWndReceiveMessage function
any other suggestions?
|
|
02-17-2009 10:33 PM |
|
|
SquidWeed
New Member
Posts: 5
Joined: Jan 2009
|
O.P. RE: [Help] ChatWndReceiveMessage function
Last bump I guess,
|
|
02-22-2009 11:34 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: [Help] ChatWndReceiveMessage function
Your code is wrong. What is happening is that the random number generated can potentially be 4 because the length of the array is 4. However an Array is zero based meaning it starts counting at 0 not 1. Therefore you need to have msgs.length-1. Like so: When you are using Math.floor you do not need to subtract 1 from the length of the array
js code: function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){
if(activated && contact.Name==Origin) ChatWnd.SendMessage(msgs[Math.floor(Math.random()*msgs.length)]);
}
You need to use Math.floor not Math.ceil. Math.floor will round down to the nearest integer where Math.ceil rounds upwards.
This post was edited on 02-23-2009 at 02:22 PM by matty.
|
|
02-22-2009 11:49 PM |
|
|
|