+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Programming Languages & Scripting (/forum-8.html)
I've been tricking around with HTML5 and I'm making a snake clone. When ever a piece of food is eaten the code calculates a new empty location in the world. This works fine for a good portion (~90%) of the play testing I've done so far.
Quote:"Uncaught TypeError: Cannot read property '5' of undefined"
It's not always '5' either so there's no pattern there. The game continues to play (everything is rendered and I can move the snake around) but no more food appears on screen.
I'm using a 2D array (an array of arrays) to represent the game world in grid form. My code for placing a new food item is:
Does anyone have any ideas?
GenerateRandomNumber(0, N) sometimes returns N. You should either pass worldWidth - 1 & worldHeight - 1, or you should set range to max - min (no + 1) in GenerateRandomNumber.
(Nov 27, 2010 01:22 PM)OneSadCookie Wrote: GenerateRandomNumber(0, N) sometimes returns N. You should either pass worldWidth - 1 & worldHeight - 1, or you should set range to max - min (no + 1) in GenerateRandomNumber.
D'oh I can't believe I didn't pick that up. I ran a few tests and that's solved the problem.
Thank you very much!