What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » My first script.

My first script.
Author: Message:
devilz-fury
Junior Member
**

Avatar

Posts: 17
Reputation: -6
29 / Male / –
Joined: Nov 2006
O.P. My first script.
This is a dead simple script. All it does is it reads a text file every 10 minutes, picks out a random non-blank line from that file and then sets that as your Personal Message on Messenger. You could use this script with IRC logs, a list of quotes, etc. It didn't take long to make.

Source Code
function updateMessage() {    FileSystem = new ActiveXObject("Scripting.FileSystemObject");    file = FileSystem.OpenTextFile("E:/Documents/testfile.txt", 1);    i = 0;    lines = new Array();    while(!file.AtEndOfStream) {        line = file.ReadLine();        if (line != '') {            lines[i] = line;        }        i++;    }    file.Close();    linenum = Math.floor(Math.random()*lines.length)-1;        Messenger.MyPersonalMessage = lines[linenum];}function OnEvent_Initialize(MessengerExit) { }function OnEvent_Uninitialize(MessengerExit) { }function OnEvent_Signin(email) {    if (email == Messenger.MyEmail) {        updateMessage();        MsgPlus.AddTimer('randomtext', 600000);    }}function OnEvent_Timer(timerId) {    if (timerId == 'randomtext') {        updateMessage();        MsgPlus.AddTimer('randomtext', 600000);    }}

Hopefully most of this script should be fairly self-explanatory. OnEvent_Signin is called when a user signs in. This function checks that it is the current user who has just signed in, and if so calls updateMessage() and schedules the next call for in 10 minutes time.

OnEvent_Timer gets called when a timer is triggered - in this case it'll get called after 10 minutes. The function calls updateMessage() and schedules the next call for in another 10 minutes time. updateMessage() opens a text file, reads the whole file putting it into an array and then selects a random line and sets it as the personal message.

Usage
To use it, go to Plus > Scripts and select "Create New". Enter a name for the script and paste the contents of the script above into it and save it. You'll have to sign out/sign in or restart Messenger to make it work. Make sure you've also changed the path to the text file which is E:/Documents/testfile.txt by default.


It'll overwrite your whole personal message. If you want it to appear as part of your personal message, concatenate the random line with something else. For example, you could change:

Messenger.MyPersonalMessage = lines[linenum];To:

Messenger.MyPersonalMessage = 'My Personal Message | '+lines[linenum]; If you want to change the update interval, change the value of 600000 (600000ms is 10 minutes).
"The World At Peace? I'd Rather See The World In Pieces."
[Image: GrimDEV.png]
[Image: Team-Exile-Member-Userbar.gif]
11-29-2006 06:39 PM
Profile E-Mail PM Find Quote Report
andrey
elite shoutboxer
****

Avatar

Posts: 795
Reputation: 48
– / Male / Flag
Joined: Aug 2004
RE: My first script.
just added a bit of layout to your script:
code:
function updateMessage() {
   FileSystem = new ActiveXObject("Scripting.FileSystemObject");
   file = FileSystem.OpenTextFile("E:/Documents/testfile.txt", 1);
   i = 0;
   lines = new Array();
   while(!file.AtEndOfStream) {
      line = file.ReadLine();
      if (line != '') {
         lines[i] = line;
      }
      i++;
   }
   file.Close();
   linenum = Math.floor(Math.random()*lines.length)-1;
   Messenger.MyPersonalMessage = lines[linenum];
}

function OnEvent_Initialize(MessengerExit) {
}

function OnEvent_Uninitialize(MessengerExit) {
}

function OnEvent_Signin(email) {
   if (email == Messenger.MyEmail) {
      updateMessage();
      MsgPlus.AddTimer('randomtext', 600000);
   }
}

function OnEvent_Timer(timerId) {
   if (timerId == 'randomtext') {
      updateMessage();
      MsgPlus.AddTimer('randomtext', 600000);
   }
}
[Image: w2kzw8qp-sq2_dz_b_xmas.png]
11-29-2006 06:58 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: My first script.
When you sign out while that script is running, your script goes *poof* kaput...


...


PS1: redundant code:
function OnEvent_Signin(email) {
     if (email == Messenger.MyEmail) {

email will always be Messenger.MyEmail btw


PS2: useless code: You don't need to include empty functions:
function OnEvent_Initialize(MessengerExit) {}
function OnEvent_Uninitialize(MessengerExit) {}


PS3: exercise code: try to optimize the updateMessage function like so:
1) get the filesize
2) get a random number from 1 to filesize
3) start reading from that offset until the next new line
4) use that next new line as your new message

tip: don't forget about methods like Skip()...


;)

This post was edited on 11-30-2006 at 01:55 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
11-30-2006 01:45 AM
Profile PM Find Quote Report
Menthix
forum admin
*******

Avatar

Posts: 5537
Reputation: 102
39 / Male / Flag
Joined: Mar 2002
RE: My first script.
quote:
Originally posted by devilz-fury
file = FileSystem.OpenTextFile("E:/Documents/testfile.txt", 1);
Somebody already made a post about this before, I'm 100% sure, but i guess he removed it. Anyway, hardlinking to a file like that will mean it will only work on your PC. By far most people don't even have an E: partition, let alone that they have that file there.
Finish the problem
Menthix.net | Contact Me
11-30-2006 01:50 AM
Profile E-Mail PM Web 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