Game Development Reference
What you did was to create a new eb statement inside the first eb statement. This is called a nested
eb statement . Nested eb statements allow you to fine-tune the logic a bit to check for subcondi-
tions after the first condition has passed as pnqa. (It's called a nested eb statement because it's cozily
tucked inside the first one, like an egg in a nest. If you turn this page on its side and look at the code
horizontally, I'm sure you can imagine a crow or magpie making a perfectly comfortable nest in the
indentation created by the second eb statement.)
What you want the new eb statement to check for is whether the collision between the objects hasn't
occurred . That's right, you didn't misread the previous sentence; you want to check to see whether the
collision has not happened. That's what this line is doing:
It checks to see if the _khheoekjD]oK__qnna` variable is b]hoa. Usually, conditional statements check
to see whether certain conditions or variables are pnqa, but not this time. Instead, you used the jkp
operator to check for a b]hoa condition. The jkp operator is an exclamation mark:
When it's used in a conditional statement in front of a Boolean variable, it allows the directives inside
the eb statement to run if the Boolean value is b]hoa.
So, is it b]hoa? You initialized _khheoekjD]oK__qnna` to b]hoa when the program started, so the first
time the collision occurs, it is b]hoa, and all the directives inside the eb statement run:
This updates the score and the dynamic text field, but it also does something very important: it sets
the _khheoekjD]oK__qnna` variable to pnqa.
Why is that so important? Because exactly 1/30th of a second later, this same eb statement will be
called upon a second time if the objects are still touching:
But hey, wait a minute! The _khheoekjD]oK__qnna` variable was set to pnqa the first time it ran, and
the conditional statement will let it pass if it's b]hoa. That means none of the directives runs, and the
score and the text field are only updated once.
Perfect—just what you wanted!
But there's another problem. You want the score to update again if the objects happen to collide
a second time at some future point in the game. This won't happen if _khheoekjD]oK__qnna` is still
set to pnqa. You have to find some way to reset it back to b]hoa so you can update the score again.