What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Random numbers, prevent from being used more than once

Random numbers, prevent from being used more than once
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Random numbers, prevent from being used more than once
quote:
Originally posted by stu
Ok, so if I was to do it as you suggest, outside my personalMessage function I would check to see what which is.. But thats not how I want the script to work though. The reason the which statement is there, is for when the script calls the personalMessage function to get a new personal message, the function can choose, by using which, if its going to be a lyric, or using my example in the script, a joke. so instead of creating 3 functions, i just have the one.
No, what I suggest is exactly how you want your script to work...

What you do now is exactly the same as using 3 functions, only you grouped them together into a 'parent' function. So, that isn't putting 3 functions into 1, that is just grouping 3 functions...

You're really making it difficult for yourself in the way you do it now ;)

quote:
Originally posted by stu
I want it to choose between a lyric and a joke each time that the script requests a new psm, and doing it outside of my function would not allow me to do so..
in that case you do not need the which checking, seperate arrays, and all that other stuff at all. Just concat the lyrics array with your quotes array and be done with it. In other words, you're REALLY making it WAY hard on yourself :P...

(and hence my initial suggestion to not alter my example routine at all but instead optimizing your code!).



-------------------

In a nutshell you would have:
code:
var Text = new Array(); // build in array or whatever... though I would indeed never ever build in a big array like that!
Text[0] = "blah1";
Text[1] = "blah2";

var arrLyrics = new Array(); // Working array
var arrPrevious = new Array(); // working array
var nUniqueness = 10; // magic


function GetAllLyrics(nWhich) {
        arrPrevious = new Array();
        switch (nWhich) {
                // use the external file quotes
                case 0: return FileToArray("C:\\quotes.txt")
                // use the internal lyrics
                case 1: return Text
                // use both
                case 2: return FileToArray("C:\\quotes.txt").concat(Text)
       
        }
}


function personalMessage() {
        Debug.Trace ("Started Personal Message");
        if (randomlyric==1) {
                var rndLyric = GetRandomLyric();
                Messenger.MyPersonalMessage = "( 8)" + rndLyric;       
                MsgPlus.DisplayToast("New Random Lyric", "( 8)" + rndLyric, null, 'OnToastClick', null);
                MsgPlus.AddTimer('randomtext', timer);
                Debug.Trace ("Printed personal message - " + rndLyric);
       }
}

function GetRandomLyric() {
etc...
etc...

Which is extremely shorter than what you have now....

GetAllLyrics() is called wherever you have your routine when the user changes the option from "quotes" to "lyrics" or to "both"....

And if you never want to implement a feature where the user can choose from which arrays the random line should be taken, you could simply only use case 2 from GetAllLyrics(). Aka: concatenate all the arrays you're going to use FIRST. Once that is done you don't need to be bothered about stuff like if (which = x) or whatever else...

----------------------------------

quote:
Originally posted by stu
Anyways, I had a question. Where you have
quote:
// EXAMPLE START (get 20 lyrics)
        arrLyrics = GetAllLyrics();
        for (var i=0; i<20; i++) {
                Debug.Trace('New lyric: ' + GetRandomLyric());
        }
// EXAMPLE END
Does that go inside my personalMessage function, or outside it like everything else?
That is example code. Code to show how you would use the above functions...

This post was edited on 07-05-2007 at 02:26 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
07-05-2007 02:00 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Random numbers, prevent from being used more than once - by stu on 07-03-2007 at 10:14 PM
RE: Random numbers, prevent from being used more than once - by pollolibredegrasa on 07-03-2007 at 10:33 PM
RE: Random numbers, prevent from being used more than once - by foaly on 07-03-2007 at 10:34 PM
RE: Random numbers, prevent from being used more than once - by roflmao456 on 07-04-2007 at 03:15 AM
RE: Random numbers, prevent from being used more than once - by Volv on 07-04-2007 at 06:01 AM
RE: Random numbers, prevent from being used more than once - by markee on 07-04-2007 at 02:17 PM
RE: Random numbers, prevent from being used more than once - by Volv on 07-04-2007 at 02:31 PM
RE: Random numbers, prevent from being used more than once - by markee on 07-04-2007 at 02:35 PM
RE: Random numbers, prevent from being used more than once - by foaly on 07-04-2007 at 04:00 PM
RE: Random numbers, prevent from being used more than once - by stu on 07-04-2007 at 04:50 PM
RE: Random numbers, prevent from being used more than once - by roflmao456 on 07-04-2007 at 05:22 PM
RE: Random numbers, prevent from being used more than once - by Volv on 07-04-2007 at 05:47 PM
RE: Random numbers, prevent from being used more than once - by CookieRevised on 07-05-2007 at 12:34 AM
RE: Random numbers, prevent from being used more than once - by stu on 07-05-2007 at 12:51 AM
RE: Random numbers, prevent from being used more than once - by CookieRevised on 07-05-2007 at 12:55 AM
RE: Random numbers, prevent from being used more than once - by stu on 07-05-2007 at 01:03 AM
RE: Random numbers, prevent from being used more than once - by CookieRevised on 07-05-2007 at 01:32 AM
RE: Random numbers, prevent from being used more than once - by stu on 07-05-2007 at 01:55 AM
RE: Random numbers, prevent from being used more than once - by CookieRevised on 07-05-2007 at 02:00 AM
RE: Random numbers, prevent from being used more than once - by stu on 07-05-2007 at 02:18 AM
RE: Random numbers, prevent from being used more than once - by CookieRevised on 07-05-2007 at 02:32 AM
RE: Random numbers, prevent from being used more than once - by Volv on 07-05-2007 at 02:45 AM
RE: Random numbers, prevent from being used more than once - by stu on 07-05-2007 at 02:51 AM
RE: Random numbers, prevent from being used more than once - by CookieRevised on 07-05-2007 at 03:07 AM
RE: Random numbers, prevent from being used more than once - by Volv on 07-05-2007 at 03:11 AM
RE: Random numbers, prevent from being used more than once - by stu on 07-05-2007 at 03:22 AM
RE: Random numbers, prevent from being used more than once - by CookieRevised on 07-05-2007 at 03:36 AM
RE: Random numbers, prevent from being used more than once - by stu on 07-05-2007 at 03:45 AM
RE: Random numbers, prevent from being used more than once - by CookieRevised on 07-05-2007 at 03:47 AM
RE: Random numbers, prevent from being used more than once - by stu on 07-05-2007 at 03:55 AM
RE: RE: Random numbers, prevent from being used more than once - by CookieRevised on 07-05-2007 at 04:23 AM
RE: Random numbers, prevent from being used more than once - by stu on 07-05-2007 at 04:30 AM
RE: Random numbers, prevent from being used more than once - by foaly on 07-05-2007 at 10:57 AM
RE: Random numbers, prevent from being used more than once - by stu on 07-05-2007 at 04:59 PM
RE: Random numbers, prevent from being used more than once - by CookieRevised on 07-05-2007 at 11:39 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