Workshop › Pinball › Step 14 of 42
A ball waiting in the lane should stay put, and Space should launch only a waiting ball. A state variable says which
of the two it is.
```js
let state // 'ready' (in the lane) or 'playing'
function newBall() {
ball = { x: LANE_X, y: 570, vx: 0, vy: 0 }
state = 'ready'
}
function update() {
if (state === 'ready') return
function launch() {
if (state !== 'ready') return
ball.vy = -16
state = 'playing'
}
```newBall() makes every new ball 'ready'.update returns at once while ready: no gravity, no move.launch does nothing unless ready (!== means "is not"), and after launching the state is 'playing'.let ball write let state.newBall, under the ball = ... line, write state = 'ready'.if (state === 'ready') return the first line of update.launch, add the first line and state = 'playing' at the end.Skills: Game states
← Small steps and a speed limit The next ball →