3D Game Programming

(C. Jardin) #1
our program (your line numbers may be slightly different). However, the
misspelled word is not on line 25 in ICE. Our problem actually happens on
line 28. And yes, JavaScript experts get confused by this as well.

Console Line Numbers Are Not Always Exact
ICE does its best to get the line numbers in the console correct,
and sometimes it succeeds—it may even be correct for you now—
but other times it can be off by a few lines. Start by looking at the
exact line number. If that doesn’t seem like it matches the error,
then check the next few lines.

Let’s get back to the “undefined is not a function” error message that is
actually referring to line 28 in ICE. This error means that when the browser
tried to run our code, it was looking for a function but found something it
knew nothing about. THREE.SpherGeometry was not defined because the actual
function was called THREE.SphereGeometry.

Luckily it’s easy to fix this problem, as all we have to do is add the e.


Possible Error Message—Three Is Not Defined


However, even after we spell SphereGeometry correctly, a ball doesn’t appear on
the screen. Something is still wrong with our code.

Looking in the JavaScript console, you should see something like the following.


Here, the JavaScript console is telling us that we forgot THREE should always
be all capital letters. There is no such thing as Three, which is what we wrote
and what the JavaScript console is telling us.

This is a very common mistake when working with the 3D library, so make
sure you remember it for the next time you see the error.

We can fix this problem by replacing the Three in the code with THREE.


Possible Error Message—Undefined: No Method


Even with those two issues fixed, the sphere is still not visible and we have
another cryptic error message in the console.

Chapter 2. Playing with the Console and Finding What’s Broken • 22


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf