Nodes/AUN ComfyUI Nodes/Text Index Switch 4
ComfyUI Node

Text Index Switch 4

The all-in-one prompt randomizer that drops the extra node

By loz2754·Created 9 months ago·Updated 11 days ago· 7
Text Index Switch 4
    • text
    • label
    • index
    ◄minimum1►
    ◄maximum10►
    ◄modeSelect►
    ◄index1►
    ◄slot_count2►
    ◄range1,2,5-8,12►
    ◄text1Slot 1►
    ◄text2Slot 2►
    ◄text3Slot 3►
    ◄text4Slot 4►
    ◄text5Slot 5►
    ◄text6Slot 6►
    ◄text7Slot 7►
    ◄text8Slot 8►
    ◄text9Slot 9►
    ◄text10Slot 10►
    ◄text11Slot 11►
    ◄text12Slot 12►
    ◄text13Slot 13►
    ◄text14Slot 14►
    ◄text15Slot 15►
    ◄text16Slot 16►
    ◄text17Slot 17►
    ◄text18Slot 18►
    ◄text19Slot 19►
    ◄text20Slot 20►

    Here's the thing most tutorial workflows hide from you: random prompt selection isn't one node, it's two. You need something to generate the index and something to switch on it. Text Index Switch 4 is the AUN pack's answer to that - it folds the index generator and the text switcher into a single node, with four selection modes, and it's the node I'd use for anything prompt-randomization related. It saves you a node and a wire, and those are the kinds of savings that add up across a hundred workflows.

    What it does

    It combines index generation (Select / Increment / Random / Range) with up to 20 text slots. You set a mode, and the node produces the index internally - no separate Random/Select INT node required - then outputs the matching text plus the label and the active index. The README's "how to randomly select a prompt" workflow uses the two-node setup with AUNRandomIndexSwitch; this node is the one-node version of that exact idea.

    Inputs that matter

    • mode - the selector: Select (fixed index), Increment (cycle through the range, great for batch runs), Random (random within range), Range (pick from a list like 1,2,5-8,12).
    • minimum / maximum - the inclusive bounds for Random/Increment modes, clamped to your slot count.
    • index - the current/target index (what Select mode uses, and what Increment cycles).
    • slot_count - how many text slots are active, 1–20.
    • range - the comma-separated index list for Range mode, e.g. 1,2,5-8,12.
    • text1–text20 - the prompt slots, multiline, with dynamic-prompt support.

    Outputs: text, label, and index (the active index - wire it into other controllers or filename builders).

    How it works

    The state lives in the node itself - it remembers its current index for Increment mode and cycles through the range, so consecutive runs step through your prompts in order. Random mode uses a proper system-random source, and Range mode parses the list (including 5-8 style spans) into a valid set, cycling through it predictably. There's also an IS_CHANGED-style re-execution trigger, so Random/Increment/Range modes actually re-run each time instead of getting cached by ComfyUI - the silent killer of "why is my random prompt stuck on the same one?" - is exactly what this avoids.

    The label works like the other switches: connected nodes contribute their titles, otherwise the slot's text stands in. And because slot_count genuinely bounds the active slots, a maximum beyond your count just clamps instead of crashing.

    Which of the four switches do you want?

    • V1 TextIndexSwitch - bare switch, cleanest when you're feeding the index from elsewhere.
    • TextIndexSwitch3 - adds the first-line-as-label convention and an index output; great for hand-organized prompt cards.
    • TextIndexSwitch4 - index generation built in, the all-in-one. This is the one for "give me random prompts" with the fewest moving parts.

    For most people, the honest answer is: start here. One node, four modes, no extra wiring.

    Installing

    Ships in the AUN ComfyUI Nodes pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/loz2754/AUN-ComfyUI-Nodes
    

    Restart ComfyUI, or use ComfyUI Manager (search "AUN"). No models, no heavy deps beyond the pack standard (auto-installed by Manager, or pip install -r custom_nodes/AUN-ComfyUI-Nodes/requirements.txt for manual clones).

    One tip before you run it: if you're using Increment mode for a batch, set maximum to exactly your slot count and keep minimum at 1 - otherwise the cycle range and the slot list can disagree, and you'll wonder why slot 12 never gets picked.

    CategoryAUN Nodes/Prompts

    Inputs (26)

    NameTypeDefaultDescription
    minimumINT11–20The minimum index for selection (inclusive).
    maximumINT101–20The maximum index for selection (inclusive).
    modeCOMBOSelectSelect mode: Select for fixed index, Increment for cycling through range, Random for random index within range, Range for selecting from a list of indices.
    indexINT11–20Current or target index, constrained by slot_count).
    slot_countINT21–20Number of visible text slots.
    rangeSTRING1,2,5-8,12A comma-separated list of indices or ranges to select from in Range mode (e.g. 1, 2, 5-8, 12).
    text1STRINGSlot 1—
    text2STRINGSlot 2—
    text3STRINGSlot 3—
    text4STRINGSlot 4—
    text5STRINGSlot 5—
    text6STRINGSlot 6—
    text7STRINGSlot 7—
    text8STRINGSlot 8—
    text9STRINGSlot 9—
    text10STRINGSlot 10—
    text11STRINGSlot 11—
    text12STRINGSlot 12—
    text13STRINGSlot 13—
    text14STRINGSlot 14—
    text15STRINGSlot 15—
    text16STRINGSlot 16—
    text17STRINGSlot 17—
    text18STRINGSlot 18—
    text19STRINGSlot 19—
    text20STRINGSlot 20—

    Outputs (3)

    NameTypeDescription
    textSTRING—
    labelSTRING—
    indexINT—