Nodes/ComfyUI Logic Support/String Switch By Number
ComfyUI Node

String Switch By Number

Pick one of fifteen prompts by a number

By narusas·Created about a year ago·Updated about a year ago· 0
String Switch By Number
    • S
    number1
    string1
    string2
    string3
    string4
    string5
    string6
    string7
    string8
    string9
    string10
    string11
    string12
    string13
    string14
    string15

    A switch is the classic way to turn "which one?" into "this one," and String Switch By Number is the ComfyUI Logic Support pack's version of it: you give it a number and up to 15 strings, and it hands back whichever string matches. The matching is 1-based - number 1 returns string1, number 5 returns string5. If the number is out of range (below 1 or above 15), it quietly falls back to string1.

    That's the whole mechanism, and it's deliberately boring. number is an INT limited to 1–15, string1 through string15 are all STRING inputs, and there's a single STRING output holding the winner. No state, no hidden behavior. It's the textbook case of a node you never think about once it's wired.

    Where it earns its keep is downstream of the pack's other number-makers. The README's canonical workflow chains Number Range Index into this node: a number (the example uses age) gets bucketed into a range, the bucket's index becomes the number here, and the node selects the text appropriate for that bucket. Same trick works off a Boolean Index Adder - whichever flag fires first determines which prompt string comes out. One number in, the right text out, no messy webs of conditional nodes.

    The one trap worth naming: the off-by-one. Because selection is 1-based, number 2 does not mean "skip the first string" in the way you might instinctively think - it literally means "give me string2." And out-of-range values silently returning string1 can bite you: if an upstream index ever computes 0 or 16, you don't get an error, you get the first option, and that can take a while to notice in a busy graph.

    Install is the same one-liner for every node in this pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/narusas/Comfyui-Logic-Support
    

    Then restart ComfyUI (or just refresh the tab). ComfyUI Manager also has it if you search for "ComfyUI Logic Support." Pure Python, zero dependencies, no models to download - nothing here can kick off the kind of dependency hell that bigger packs bring with them. MIT-licensed, single-author, and small enough that you won't find much community chatter about it; it's a utility you install once and forget.

    CategoryLogic-Support

    Inputs (16)

    NameTypeDefaultDescription
    numberINT11–15
    string1STRING
    string2STRING
    string3STRING
    string4STRING
    string5STRING
    string6STRING
    string7STRING
    string8STRING
    string9STRING
    string10STRING
    string11STRING
    string12STRING
    string13STRING
    string14STRING
    string15STRING

    Outputs (1)

    NameTypeDescription
    SSTRING