Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to make an equation into a variable

Status
Not open for further replies.

fiuPikeOY

Programmer
Jun 14, 2004
143
US
Hello,

I have several arrays that are like this...

ch1sounds['test1.mp3', 'test2.mp3'...]
ch2sounds['test1.mp3', 'test2.mp3'...]
ch3sounds['test1.mp3', 'test2.mp3'...]

and I have the following expression to get the correct sound file to play

soundToLoad = "ch" + chapter+ "sounds[" + i + "]";

but this is returning for ch1sounds[0], and I need it to return the value of ch1sounds[0], which is test1.mp3. I tried the eval function and it's returning undefined.

What am I doing wrong?

Thanks in advance

 
Try using eval like this:

Code:
soundToLoad = eval("ch"+chapter+"sounds")[i];

frozenpeas
 
i think you are trying to complicate it

soundToLoad = "ch"+chapter+"sounds"+i;

ought to do given that chapter and i are the variables
 
Actually, I solved the problem by using a 2-dimensional array.

Bill, remember that it's reading from an array so you would need the [] there somewhere right?

Thanks to both.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top