Workshop › Candy Crush-style Match 3 › Step 24 of 29

A hint after five seconds

What we are doing

hasMove also gives a hint. idleFor counts the idle frames; after 300 (five seconds) the hint is a possible move. Making a move clears it.

```js
let idleFor // frames since the last move
let hint // a possible move, shown after five idle seconds

function reset() {
  // ...
  idleFor = 0
  hint = null
}

function trySwap(a, b) {
  // ...
  chain = 0
  idleFor = 0
  hint = null
  startClearing()

function update() {
  // ...
  if (phase === 'falling') {
    // ...
    return
  }
  idleFor += 1
  if (idleFor === 300) hint = hasMove()
}
```

What it means

Your turn

  1. Under let drop write let idleFor and let hint.
  2. In reset, at the end, and in trySwap, under chain = 0, write idleFor = 0 and hint = null.
  3. In update, write return at the end of the 'falling' block, and the two idleFor lines at the end of the function.

Skills: Game states, The game loop

All steps

  1. A place for the board
  2. A checkered grid
  3. The game loop
  4. A board of random gems
  5. Draw the gems
  6. Start without matches
  7. Click a gem
  8. Show the selection
  9. Swap two neighbours
  10. Find every match
  11. No match, no swap
  12. A score and a fresh start
  13. Clear the match
  14. Let the gems fall
  15. Two halves of a clear
  16. Wait before clearing
  17. Flash, and hands off
  18. Cascades
  19. Where a gem came from
  20. Slide down
  21. Out from under the top
  22. Is there any move?
  23. Never stuck
  24. A hint after five seconds
  25. Show the hint
  26. Twenty moves
  27. The end of a game
  28. Remember the best score
  29. Build it yourself: swipe to swap