-
Senior Member
Freezing Loops
Hey, I am making something that searches through a starting amount of 200 words, and then if it finds that an entered word doesnt match any of those, it adds it to those 200. Here is the starting script (manual word is the entered word to be checked).
code:
function prepare2(){
words.toLowerCase();
manualWord.toLowerCase();
for (t = 1; t <= totalWords; t++){
if (words[t] == manualWord){
wordNumber = t;
detected = 1;
}
}
return detected;
matches = undefined;
typeGame = undefined;
wrongText = "";
aG = false
bG = false
cG = false
dG = false
eG = false
fG = false
gG = false
hG = false
iG = false
jG = false
kG = false
lG = false
mG = false
nG = false
oG = false
pG = false
qG = false
rG = false
sG = false
tG = false
uG = false
vG = false
wG = false
xG = false
yG = false
zG = false
if (detected == []){
addWord(manualWord);
}
redirectTwo();
}
Heres is the addWord() function, and all the things related to it:
code:
//Saving
var saver:SharedObject = SharedObject.getLocal("tester4");
if (saver.data.playedBefore == undefined){
saver.data.playedBefore = true;
saver.data.savedWords = words;
var totalWords:Number = 200;
saver.data.totalWords = totalWords;
saver.flush();
trace(saver.data.totalWords);
}else{
words = saver.data.savedWords;
}
function addWord(newWord){
totalWords ++;
wordNumber = totalWords;
saver.data.totalWords = totalWords;
words[totalWords] = newWord;
saver.data.savedWords = words;
saver.flush();
}
Now, whenever it performs the loop, the alert popup that says it is running slowly comes up. Is there a way to fix this problem?
Last edited by SpikeyOmega; 06-18-2005 at 07:12 PM.
-
Code:
// testing - populate an array (words)
var words = new Array ();
for (var i = 0; i < 200; i++)
{
words.push ('word' + i);
}
// changed the way the word is passed to the function
function prepare2 (word)
{
// convert the word to lowercase
var mwc = word.toLowerCase ();
for (t = 1; t <= words.length; t++)
{
if (words[t].toLowerCase () == mwc)
{
// if there is a match stop the loop
return true;
}
}
// if we've reached here - the word is not in the array, so add it
addWord (word);
redirectTwo ();
// end the function
return false;
}
// simulated
function redirectTwo ()
{
trace ('redirectTwo');
}
// simulated to show it working
onMouseDown = function ()
{
// word will be addd on mouse down - testing
prepare2 ('notinarray');
// word is already in array - not added
prepare2 ('word2');
};
//Saving
var saver:SharedObject = SharedObject.getLocal ("tester6");
if (saver.data.savedWords == undefined)
{
saver.data.savedWords = words;
saver.data.totalWords = words.length;
trace (saver.data.totalWords);
}
else
{
words = saver.data.savedWords;
}
function addWord (newWord)
{
trace ('adding word');
saver.data.savedWords.push (newWord);
saver.data.totalWords = words.length;
}
-
Senior Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|