Workshop › Pinball › Step 32 of 42
A game has three balls. Each drained ball uses one; when none are left the state becomes 'over' and the physics
stops.
```js
let state // 'ready' (in the lane), 'playing' or 'over'
let balls
balls = 3
if (state !== 'playing') return
if (ball.y > canvas.height + R) {
balls -= 1
if (balls > 0) newBall()
else {
state = 'over'
}
}
```reset gives three balls.'over'.if (state !== 'playing') return after the ready block stops the physics when the game is over; without it the
lost ball would keep falling and take away a ball every frame.let state; under let score write let balls.reset, under score = 0, write balls = 3.update, under the ready block's }, write if (state !== 'playing') return.update (the drained ball) with the new block.Skills: Game states
← The flipper throws Balls left and game over →