3D Game Programming

(C. Jardin) #1
At first we’re not done with the game. Then, some time later, we are. If we
wrote code where it says, // do some work here, that code would think that the
game is still in progress. Being able to update variables will come in handy
shortly.

About that line that starts with two slashes...


Comments


Double slashes indicate comments. The computer knows it’s supposed to
ignore everything on the line that follows //. In other words, comments are for
people only:

// This returns today's date
vartoday =newDate();

// This is January 1, 2013
varjan1 =newDate(2013, 1, 1);

You Don’t Need to Type the Comments
The comments you see in this book are meant to give you helpful
hints. You don’t need to type them in, but you should. Comments
will help you to remember why you did things when you open your
code later to make a change.

Really, you should be adding your own comments as well.


7.3 Changing Things


We know that we can change things, but how can each kind of variable change
in JavaScript? Let’s take them one at a time.

Numbers


You can use standard math symbols to add and subtract numbers in Java-
Script. Try the following in the JavaScript console:

5 + 2;
10 - 9.5;
23 - 46;
84 + -42;

You should get back the following answers (the answer is shown in the com-
ments below the math problem).

5 + 2;
// 7

report erratum • discuss

Changing Things • 69


Prepared exclusively for Michael Powell

Free download pdf