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