Thursday, August 6, 2009
MJW Avoider Game ep11ch1
Alrighty-- Another challenge! I already wrote below about my fun with isNaN during this challenge. But let me try to document what I did for the challenge itself. Won't be too long...
Staying in the GameOverScreen.as file, I added the following to the constructor. (I called my array bestScoreArray) I wanted to check if the array was undefined or empty, and if so, create it.
Then, I figured I'd plug information when the final score was set. So down in the setFinalScre function:
I'm grabbing three pieces of information and sticking it in an array -- score, total number of games played when that score was reached, and an arbitrary string of text just to test.
Ok, now I need to make sure it's working, so I threw this down below in the same 'setFinalScore' function. It will loop through the array and 'trace' every item to the output window.
Now run it.
D'oh! Didn't work... why not? Looking back through my code I realized this was wrong:
Can you spot why? Because we're creating an array... so it's NEVER going to be a "number" (isNaN checks if something is 'not a number')
So, change that to this, and try again:
Voila! Should work now. If you have any problems, let me know.