Skip to content

Note Iterators

Swifter edited this page Nov 3, 2024 · 3 revisions

Prerequisites

How To Use

Note iterators are designed to run notes through a sequence of "conditions" and "processes" in order to modularly create notemod effects that would normally have to be written with a direct for loop.

rm.noteIterator()
    .betweenTime(0, 20)
    .betweenXPositions(0, 2)
    .addTrack('myNote')
    .run(map)
  • Note: this is equivalent to:
map.allNotes.forEach(note => {
    const inTime = note.beat >= 0 && note.beat < 20
    const inPosition = note.x >= 0 && note.x < 2
    
    if (inTime && inPosition) {
        note.track.add('myNote')
    }
})

Conditions/Processes

When the run function is called on a note iterator, it will run all of the conditions on every note in the provided difficulty. Based on whatever notes pass all of the conditions, all of the processes will then be run on each one.

There are lots of provided conditions (example: betweenTime) and processes (example: addTrack) but you can also add your own.

rm.noteIterator()
    .addCondition(note => {
        return note.beat < 20
    })
    .addProcess(note => {
        note.beat += 1
    })
    .run(map)
  • The addCondition function accepts a function parameter that takes in a note and returns true or false. It adds this function to it's internal conditions.
  • The addProcess function accepts a function parameter that takes in a note and returns nothing. It adds this function to it's internal processes.

You can process an array of notes through a note iterator with the processNotes function.

rm.noteIterator()
    .addTrack('myNotesTrack')
    .processNotes(myNotes)

Note Type Filtering

Note iterators work with all note types by default. If you wish to only filter a certain type of notes, you can use the onlyArcs, onlyBombs, onlyChains, onlyColorNotes, and setTypeFilter functions.

rm.noteIterator()
    .onlyArcs()
    .addTrack('myArc')
    .run(map)

The code snippet above will allow only arcs to pass. But on top of that, it also types the entire class so that all conditions and processes only operate on Arcs.

image

If you wish to filter more than one type of note, the setTypeFilter function will allow you to pass an array of strings to represent each note type you want.

rm.noteIterator()
    .setTypeFilter(['Arc', 'Bomb'])
    .run(map) // only runs on Arcs and Bombs.

Clone this wiki locally