...

View Full Version : Getting the value of a variable from another function.



Grass™
06-01-2007, 06:01 PM
Heres what i got, ignore all the unknowns they come from textboxes etc.

My problem is in this function I change the value of a variable. I want to store that variable change so i can use it in another function. Heres what i got.



function setupGame(){
var guessesLeft = guessNo.value = 10;
var wordSplice = new Array();
wordVal = word.value
wordVal = wordVal.toLowerCase();
alert(wordVal);
for(var i=0; i<wordVal.length; i++){
wordSplice[i] = wordVal.substring(i, i+1);
wordSoFar.value += "*"
}
}


Thats the first function, the variable or 'Array' values of wordSplice I saved I want to use in this function :



function runCoreEngine(){
for(i in wordSplice){
}
}


Really appreciate any help, if theres anything I was unclear on let me know I really need a solution. Cheers!

glenngv
06-01-2007, 06:14 PM
That variable should be global. Declare it outside the function.

var wordSplice;
function setupGame(){
var guessesLeft = guessNo.value = 10;
wordSplice = new Array();
wordVal = word.value
wordVal = wordVal.toLowerCase();
alert(wordVal);
for(var i=0; i<wordVal.length; i++){
wordSplice[i] = wordVal.substring(i, i+1);
wordSoFar.value += "*"
}
}

Grass™
06-01-2007, 06:22 PM
Hey Thanks it worked, it was weird I tried that originally, didint work but then i added "= new Array()" to the end of the global one it worked.


Cheers mate.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum