What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [help needed] randomly send a word from a list

[help needed] randomly send a word from a list
Author: Message:
phalanxii
Full Member
***


Posts: 146
Reputation: 5
32 / Male / Flag
Joined: Aug 2006
Status: Away
RE: [help needed] randomly send a word from a list
It really depends on how you want the script to work. Here are three scripts.

Let's say you want it to send a random word when you send a message saying "moo!" (and only "moo!").
code:
var RandomWordList = new Array("box", "ship", "letter");

function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
   if(Message == "moo!") {
      return RandomWordList[Math.floor(Math.random() * RandomWordList.length)];
   }
}
The random words can be added to RandomWordList separated by commas and surrounded by quotation marks. There is no limit for how many words you want in the list. This script will send a random word when you send a message containing "moo!" exactly (case-sensitive), replacing "moo!".

Now, let's say you want it to replace all the "moo!"s in your message with a random word.
code:
var RandomWordList = new Array("box", "ship", "letter");

function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
   return Message.replace(/moo!/g, RandomWordList[Math.floor(Math.random() * RandomWordList.length)]);
}
Again, we use the RandomWordList array. This time, you can type whatever you want with a "moo!" in it and it will replace it with a random word. This is also case-sensitive

Finally, here is a code identical to the above, except it replaces "moo!" with different random words each time (if there is more that one "moo!' in a message).
code:
var RandomWordList = new Array("box", "ship", "letter");

function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
   while(Message.match(/moo!/) != null) {
      return Message.replace(/moo!/, RandomWordList[Math.floor(Math.random() * RandomWordList.length)]);
   }
}
This also uses the RandomWordList array. This is identical to the above, except if you send a message "I like moo! moo!", instead of seeing (for example) "I like box box", you will see something like "I like letter box".

Hope these are close to what you need. I haven't tested them, so look out for bugs or infinite loops. :S

EDIT: JayJay's random is better. :)

This post was edited on 09-16-2006 at 11:17 PM by phalanxii.
09-16-2006 11:04 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[help needed] randomly send a word from a list - by skyserpent on 09-16-2006 at 10:17 PM
RE: [help needed] randomly send a word from a list - by NanaFreak on 09-16-2006 at 10:58 PM
RE: [help needed] randomly send a word from a list - by phalanxii on 09-16-2006 at 11:04 PM
RE: [help needed] randomly send a word from a list - by skyserpent on 09-17-2006 at 01:22 AM


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