Shoutbox

Use existing array to generate random quote in personal message? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Use existing array to generate random quote in personal message? (/showthread.php?tid=75156)

Use existing array to generate random quote in personal message? by stu on 06-07-2007 at 08:37 PM

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();

// -->

RE: Use existing array to generate random quote in personal message? by albert on 06-07-2007 at 10:10 PM

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..


RE: Use existing array to generate random quote in personal message? by albert on 06-08-2007 at 01:24 AM

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.
RE: Use existing array to generate random quote in personal message? by stu on 06-08-2007 at 01:55 AM

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?


RE: Use existing array to generate random quote in personal message? by albert on 06-08-2007 at 02:19 AM

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.


RE: Use existing array to generate random quote in personal message? by stu on 06-08-2007 at 02:33 AM

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.


RE: Use existing array to generate random quote in personal message? by albert on 06-08-2007 at 03:47 AM

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.


RE: Use existing array to generate random quote in personal message? by stu on 06-08-2007 at 12:26 PM

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


RE: Use existing array to generate random quote in personal message? by stu on 06-09-2007 at 12:25 AM

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