Nodes/NH-Nodes/Text Index (NH)
ComfyUI Node

Text Index (NH)

Pick the Nth prompt out of a stack, and stop when there's nothing to pick

By jetthuangai·Created 6 months ago·Updated about a month ago· 7
Text Index (NH)
    • text
    ◄index1►
    ◄text_count5►
    ◄text_1►
    ◄text_2►
    ◄text_3►
    ◄text_4►
    ◄text_5►
    ◄text_6►
    ◄text_7►
    ◄text_8►
    ◄text_9►
    ◄text_10►
    ◄text_11►
    ◄text_12►
    ◄text_13►
    ◄text_14►
    ◄text_15►
    ◄text_16►
    ◄text_17►
    ◄text_18►
    ◄text_19►
    ◄text_20►
    ◄text_21►
    ◄text_22►
    ◄text_23►
    ◄text_24►
    ◄text_25►
    ◄text_26►
    ◄text_27►
    ◄text_28►
    ◄text_29►
    ◄text_30►
    ◄text_31►
    ◄text_32►
    ◄text_33►
    ◄text_34►
    ◄text_35►
    ◄text_36►
    ◄text_37►
    ◄text_38►
    ◄text_39►
    ◄text_40►
    ◄text_41►
    ◄text_42►
    ◄text_43►
    ◄text_44►
    ◄text_45►
    ◄text_46►
    ◄text_47►
    ◄text_48►
    ◄text_49►
    ◄text_50►
    ◄text_51►
    ◄text_52►
    ◄text_53►
    ◄text_54►
    ◄text_55►
    ◄text_56►
    ◄text_57►
    ◄text_58►
    ◄text_59►
    ◄text_60►
    ◄text_61►
    ◄text_62►
    ◄text_63►
    ◄text_64►

    When you've got a stack of prompts - one per shot, one per variation, one per folder - the obvious move is an index: "give me the third one." Text Index (NH) does exactly that, and it's careful about the edge cases in a way that makes it genuinely safer than a naive pick.

    You tell it how many slots you're using with text_count (default 5, max 64) and which one you want with index. The node exposes text_1 through text_N multiline inputs and returns the one at index as a single STRING. It's one-based, because people - and ComfyUI - think in one-based when they're counting prompts, so slot 1 is text_1, not slot 0. That's the first thing to double-check if the "wrong" prompt comes out: you're off by one from whatever system you're used to.

    The interesting part is what happens at the boundaries. This isn't a node that returns None or an empty string and lets garbage flow downstream. If the index is out of range (say index 5 but text_count 3), or the selected slot is empty, the node returns an execution blocker - a special value that tells ComfyUI to skip everything downstream of it rather than run with a bogus prompt. So a workflow asking for prompt 7 of a 5-prompt stack doesn't generate a nonsense image; it just doesn't generate that branch at all. That's a design choice worth appreciating: an explicit "stop here" beats a silent empty prompt every time.

    Why you'd use it

    The natural consumer is a batch or animation workflow where a counter steps index and each step samples a different prompt - feed the output into a CLIP encoder, same as any prompt. It also pairs beautifully with a Switch N or a Random Choice upstream if you want to choose which index to read rather than hardcode it. The text_count cap of 64 keeps it honest for big stacks, and since the slots are multiline, each prompt can itself be a multi-line block.

    Install

    It's part of NH-Nodes:

    • ComfyUI Manager → search NH-Nodes → install → restart ComfyUI. Or manually:
    cd ComfyUI/custom_nodes
    git clone https://github.com/jetthuangai/NH-Nodes.git
    cd NH-Nodes
    pip install -r requirements.txt
    

    Then restart ComfyUI.

    No models or heavy deps - plain string plumbing.

    Common issues

    The two failure modes are both "nothing comes out," and they're distinguishable: an out-of-range index or an empty slot blocks execution downstream (the graph just stops there), while a valid index with a filled slot always produces text. If a branch silently produces no image, your first check is index vs text_count. And the off-by-one: if the prompt "one before the one I picked" shows up, remember it's 1-based. Keep index visible and you'll spot either in a glance.

    CategoryNH-Nodes/Text

    Inputs (66)

    NameTypeDefaultDescription
    indexINT11–64—
    text_countINT51–64—
    text_1optSTRING—
    text_2optSTRING—
    text_3optSTRING—
    text_4optSTRING—
    text_5optSTRING—
    text_6optSTRING—
    text_7optSTRING—
    text_8optSTRING—
    text_9optSTRING—
    text_10optSTRING—
    text_11optSTRING—
    text_12optSTRING—
    text_13optSTRING—
    text_14optSTRING—
    text_15optSTRING—
    text_16optSTRING—
    text_17optSTRING—
    text_18optSTRING—
    text_19optSTRING—
    text_20optSTRING—
    text_21optSTRING—
    text_22optSTRING—
    text_23optSTRING—
    text_24optSTRING—
    text_25optSTRING—
    text_26optSTRING—
    text_27optSTRING—
    text_28optSTRING—
    text_29optSTRING—
    text_30optSTRING—
    text_31optSTRING—
    text_32optSTRING—
    text_33optSTRING—
    text_34optSTRING—
    text_35optSTRING—
    text_36optSTRING—
    text_37optSTRING—
    text_38optSTRING—
    text_39optSTRING—
    text_40optSTRING—
    text_41optSTRING—
    text_42optSTRING—
    text_43optSTRING—
    text_44optSTRING—
    text_45optSTRING—
    text_46optSTRING—
    text_47optSTRING—
    text_48optSTRING—
    text_49optSTRING—
    text_50optSTRING—
    text_51optSTRING—
    text_52optSTRING—
    text_53optSTRING—
    text_54optSTRING—
    text_55optSTRING—
    text_56optSTRING—
    text_57optSTRING—
    text_58optSTRING—
    text_59optSTRING—
    text_60optSTRING—
    text_61optSTRING—
    text_62optSTRING—
    text_63optSTRING—
    text_64optSTRING—

    Outputs (1)

    NameTypeDescription
    textSTRING—