What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Use existing array to generate random quote in personal message?

Use existing array to generate random quote in personal message?
Author: Message:
stu
Junior Member
**

Avatar
Stu

Posts: 82
Reputation: 1
39 / Male / Flag
Joined: Sep 2004
O.P. Undecided  Use existing array to generate random quote in personal message?
I have some javascript code that I use for my website to generate and display a random song lyric. Im wondering if it would be possible to use my existing code, shown below, with a script to show a random lyric as my personal message. I know there are other scripts out there that can do this, but seeing as I already have this set up and update it frequently, it would be great if I could use this code. Does anybody have any suggestions on how to do this or could write something up quick? Thanks for any help :)

code:
<!--

var Text=new Array()
var num=0;

Text[num++] = "Song quote one";

Text[num++] = "Song quote two";

Text[num++] = "Song quote three.. etc";

var Number=Math.round(Math.random()*(num-1));
function showText(){document.write("<p class=\"lyric\">Music Quote</p> <div>&#9834;" + Text[Number] + "&#9834;</div>");}
showText();

// -->
06-07-2007 08:37 PM
Profile E-Mail PM Web Find Quote Report
albert
Veteran Member
*****

Avatar

Posts: 2247
Reputation: 42
– / Male / Flag
Joined: Feb 2005
RE: Use existing array to generate random quote in personal message?
What you could do easily is to put your quotes in a text file, then read a certain amount of line generated by the random number, and set the personal message to display that line. It shouldn't be hard to do, I'll give it a try once I get my home computer started (I'm at work now.)

As for using the array that you already have created, you could just copy paste it into the script..

This post was edited on 06-07-2007 at 10:12 PM by albert.
06-07-2007 10:10 PM
Profile E-Mail PM Web Find Quote Report
albert
Veteran Member
*****

Avatar

Posts: 2247
Reputation: 42
– / Male / Flag
Joined: Feb 2005
RE: Use existing array to generate random quote in personal message?
Bump :

here's the script I made you. It works pretty simply, it reads quotes out of a text file, and then displays one randomly in your personal message every time you start Windows Live Messenger.

You can change the fileLocation to the path you desire, just remember to change the \ for a double. (\\)

Depending on the number of quotes you have, you also have to change the numberOfQuotes number, and put the number of lines you have (should be easy since you kept it in an array, therefore you know how many rows you have..).

I hope it helps, here's the code :

code:
function OnEvent_Initialize(MessengerStart)
{
    numberOfQuotes = 18 ;
    fileLocation = "C:\\quotes.txt" ;

    fileStream = new ActiveXObject("Scripting.FileSystemObject");
    f = fileStream.OpenTextFile( fileLocation, 1, true) ;

    randomNumber = Math.random( ) * numberOfQuotes  ;

    for ( var i = 0 ; i < randomNumber ; i ++ )
        quoteSelected = f.ReadLine( ) ;
   
    Messenger.MyPersonalMessage = quoteSelected ;
}

function OnEvent_Uninitialize(MessengerExit)
{
}


Report any problems.

This post was edited on 06-08-2007 at 01:36 AM by albert.
06-08-2007 01:24 AM
Profile E-Mail PM Web Find Quote Report
stu
Junior Member
**

Avatar
Stu

Posts: 82
Reputation: 1
39 / Male / Flag
Joined: Sep 2004
O.P. RE: Use existing array to generate random quote in personal message?
Hey thanks for the reply. Yeah, I know that you can read quotes straight out of a text file like that, but thats not exactly what I am looking for. I have probably a couple hundred quotes using the code that I have posted above, and what I want to do, is have a script that will read the array out my already created .js script file. I would just rather have only one file with my quotes, and as I already have this one set up, would prefer to use it.

So would there be a way to open my file (songs.js) with a Plus! script, and somehow get that to display as my personal message? Or am I just SOL and have to create two different files with quotes?
06-08-2007 01:55 AM
Profile E-Mail PM Web Find Quote Report
albert
Veteran Member
*****

Avatar

Posts: 2247
Reputation: 42
– / Male / Flag
Joined: Feb 2005
RE: Use existing array to generate random quote in personal message?
You mind sending me that file?
If I'm correct you could simply copy/paste the array in there.

Although, if you really don't want to copy paste the text from a js file to another, I don't know how to help you really.

I don't know if it's possible.. Maybe someone else can help, sorry.

This post was edited on 06-08-2007 at 02:20 AM by albert.
06-08-2007 02:19 AM
Profile E-Mail PM Web Find Quote Report
stu
Junior Member
**

Avatar
Stu

Posts: 82
Reputation: 1
39 / Male / Flag
Joined: Sep 2004
O.P. RE: Use existing array to generate random quote in personal message?
Sure thing, I'll attach it here. Had to change to a .txt extension, wouldnt let me upload as .js. Its the exact same as what I had my first post though, only longer. Thanks for taking a look.

.txt File Attachment: songs.txt (88.56 KB)
This file has been downloaded 109 time(s).
06-08-2007 02:33 AM
Profile E-Mail PM Web Find Quote Report
albert
Veteran Member
*****

Avatar

Posts: 2247
Reputation: 42
– / Male / Flag
Joined: Feb 2005
RE: Use existing array to generate random quote in personal message?
Well Stu, the best I can do is attached with this post, what I did is simply copy/paste the array that you have created and then did a random search and then loaded the personal message with the random found string.

I know it isn't exactly as you wished, but that's all I know how to fix.. Maybe someone else can do better.

.txt File Attachment: Random_Quotes.txt (88.48 KB)
This file has been downloaded 155 time(s).
06-08-2007 03:47 AM
Profile E-Mail PM Web Find Quote Report
stu
Junior Member
**

Avatar
Stu

Posts: 82
Reputation: 1
39 / Male / Flag
Joined: Sep 2004
O.P. RE: Use existing array to generate random quote in personal message?
Ok, thanks a lot alby, its appreciated. I will use that for now anyways, if anyone else has any other ideas that would be great as well. Thanks
06-08-2007 12:26 PM
Profile E-Mail PM Web Find Quote Report
stu
Junior Member
**

Avatar
Stu

Posts: 82
Reputation: 1
39 / Male / Flag
Joined: Sep 2004
O.P. RE: Use existing array to generate random quote in personal message?
Is there a way to read the entire file once its opened instead of just one line?
code:
quoteSelected = f.ReadLine( ) ;
If theres a way around that, I believe I could get a script to work with my own code *-)

Sorry for double post lol

This post was edited on 06-09-2007 at 12:25 AM by stu.
06-09-2007 12:25 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