Workshop › Rhythm Lanes › Step 7 of 35
The game needs notes, not text. Every 1 in the chart becomes a note object { lane, time, hit }, where time is
the frame at which it must be hit.
```js
const STEP = 15 // frames between rows of the chart (an eighth note at 120 beats a minute)
const LEAD = 120 // frames before the first row reaches the line
let notes // { lane, time, hit }
function reset() {
notes = []
CHART.forEach((row, i) => {
for (let lane = 0; lane < LANES; lane++) if (row[lane] === '1') notes.push({ lane, time: LEAD + i * STEP, hit: false })
})
}
reset()
draw()
```CHART.forEach((row, i) => ...) runs once for each row: row is its text, i its number.for loop looks at the row's four characters; each '1' pushes a note onto notes.i must be hit at frame LEAD + i * STEP. { lane, ... } is short for { lane: lane, ... }.reset() builds the notes once, before the first draw().HIT_Y, write STEP and LEAD.CHART, after an empty line, write let notes and reset.reset() above draw().Skills: Arrays and objects, Loops
← The song as text The clock decides where →