What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help] ChatWndReceiveMessage function

[Help] ChatWndReceiveMessage function
Author: Message:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
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
Javascript 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
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[Help] ChatWndReceiveMessage function - by SquidWeed on 01-28-2009 at 10:52 PM
RE: [Help] ChatWndReceiveMessage function - by djdannyp on 01-28-2009 at 11:04 PM
RE: [Help] ChatWndReceiveMessage function - by SquidWeed on 01-28-2009 at 11:15 PM
RE: [Help] ChatWndReceiveMessage function - by Matti on 01-29-2009 at 04:50 PM
RE: [Help] ChatWndReceiveMessage function - by Spunky on 01-29-2009 at 06:31 PM
RE: [Help] ChatWndReceiveMessage function - by SquidWeed on 01-30-2009 at 02:44 AM
RE: [Help] ChatWndReceiveMessage function - by SquidWeed on 02-17-2009 at 10:33 PM
RE: [Help] ChatWndReceiveMessage function - by SquidWeed on 02-22-2009 at 11:34 PM
RE: [Help] ChatWndReceiveMessage function - by matty on 02-22-2009 at 11:49 PM


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