Don't understand why hasStarted works

Hi,

Welcome to our community! :slight_smile:

Our idea is the following: When the game starts, we want to have the ball move along with the paddle. And the ball should continue following the paddle until the player launches the ball.

In programming, we often use an if-statement to express a restriction. Here the restriction is: (hasStarted == false). By hasStarted, we mean: As long as the ball was not launched.

In the method where we launch the ball, there is supposed to be a line of code which sets hasStarted to true, so the if-block in the Update method will not get executed anymore.

The computer is not intelligent. It cannot think, and it does not understand our ideas. For this reason, we have to provide clear instructions such as: Do this, do that; if this, then that. And so on.

If you still find the code hard to grasp, take a pen and a sheet of paper and draw a diagram which visualises the logic/concept (not the code!). Rick is trying to solve a problem: Make the ball follow the paddle when the Play button was pressed, and make the ball move by physics engine after the right mouse button was pressed. Since the computer does not know anything about “ball”, “paddle”, “after” or “physics engine”, we need a more abstract solution.

Once you grasped Rick’s idea, I’m sure the code will make more sense. The code is just a way to express the concept in a way the computer can “understand”.

Did this help?


See also: