Nodes/ComfyUI-JNK-Tiny-Nodes/Switch Index JNK
ComfyUI Node

Switch Index JNK

A little ON/OFF toggle that outputs 2 or 1

By AljnkΒ·Created about a year agoΒ·Updated 12 months agoΒ· 3
Switch Index JNK
    • int
    β—„stateONβ–Ί

    This is the most boring node in the pack, and it earns its place because ComfyUI's logic wiring sometimes needs a number, not a state. "Switch Index JNK" is a single ON/OFF dropdown that outputs 2 when ON and 1 when OFF. That's the entire job. If that seems too trivial to be useful, you haven't met an index-based switch node yet.

    The reason for the weird numbering lives in the pack's own design. Its "Load Image if Exist" node returns an index of 1 when a file loads and 2 when it doesn't - a convention where 1 means "the good path" and 2 means "the fallback path," and 0 is reserved for "nothing happened." Index-driven switch nodes (and several community packs use the same 1/2 convention) pick their branch by that number. So Switch Index is a human-readable toggle that speaks the machine's language: flip it ON and downstream switching logic picks the first input; flip it OFF and it picks the second. You get a labeled toggle in your UI instead of a mystery integer buried in a primitive.

    Mechanically it's a two-line function - if state == "ON": return 2 else: return 1 - with no caching and no statefulness. It re-evaluates every run, so you can flip the dropdown mid-batch and the next execution picks it up immediately. The single input is the state dropdown (ON/OFF, default ON) and the single output is int.

    Where you'd actually reach for it: feeding a conditional into an index-based switch, gate, or selector - something that takes an INT and chooses between two branches. The pack's "Get Text From List by Index" is a natural target. The sibling "Switch Integer JNK" does the same trick but outputs 1/0 for ON/OFF, which suits the different convention of multiplier and mask gates; this node is the one for the 1/2 world. Get both wrong and you'll know instantly - your branches will just swap, which is honestly a gentle failure mode.

    Install: ComfyUI Manager β†’ search "JNK" β†’ Install, then restart. Or:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/Aljnk/ComfyUI-JNK-Tiny-Nodes.git
    

    Then restart. No dependencies beyond ComfyUI itself.

    Gotchas: there aren't many, because there's nothing to break. The only real trap is expecting 0 somewhere - this node never outputs 0, so if your downstream logic treats 0 as "off," you'll feed it a 1 or 2 and wonder why nothing toggles. And don't confuse it with Switch Integer (1/0). They look identical in a packed graph; the tooltip-less name is the only hint. If you're just toggling between two branch values, it's the cleanest labeled switch you'll add all day.

    CategoryπŸ”§ JNK

    Inputs (1)

    NameTypeDefaultDescription
    stateCOMBOON2 options: ON, OFF

    Outputs (1)

    NameTypeDescription
    intINTβ€”