Pilcrow Records

Scripter Javascript Tutorial

javascriptmusiclogicscripterbookexcerpttutorial

59 Conditional Branching

MDN: Control Flow and Error Handling: Conditional Statements

Events come in a variety of types and just about any manipulation of events will require some kind of decision making about what actions to perform in certain situations. There are 4 types of branching in JavaScript, all applicable to Scripter:

  1. if for when a block of code is to be executed when the specified condition is true.

  2. else for when the specified condition is false.

  3. else if to specify a new condition when the previous one is false.

  4. switch, which is a variation on if...else if.

Conditional branching is critical to working with events being passed into HandleMIDI() and when using TimingInfo process blocks to understand which bar and division the playhead is currently in.