At index (STRING)
Pick a prompt from a list by number — batch variation without the typing
- text
You have five prompt variants and you want each image in a batch to use a different one. That's the exact job of At index (STRING) (RF_AtIndexString): give it a multi-line block of text and an index, and it returns the line at that position. Feed the index from a seed or a counter and your workflow quietly cycles through prompts as it runs. It's the RF Nodes take on prompt switching, and it's built for the batch-variation pattern people usually hack together with half a dozen switches.
How it works
Under the hood it's lines[index[0] % len(lines)] - and that single line says two important things. First, it wraps around: the modulo means the index never runs off the end of your list, so index 5 on a three-line block simply cycles back around. Second, the node declares INPUT_IS_LIST, so it accepts inputs as lists and takes the first element's index. In practice that means it plays nicely with values that arrive as batches, and it handles any index safely no matter how large.
The inputs that matter
- lines - the multi-line text block, one candidate per line. Each line is a prompt (or a filename, or any string).
- index - the line to return, zero-based (default
0). First line is 0. Out-of-range values wrap via modulo, so no errors, just rotation.
Output: text - the selected line.
The pattern worth building
Wire a seed (or a counter from a loop/batch node) into index, and put your variants in lines. Every run grabs a different prompt while keeping the same seed-driven behavior - which is exactly how you get a folder full of varied outputs from one graph. Because the wrap-around is automatic, you can even use a raw incrementing counter without guarding against overflow; it just cycles.
Installing RF Nodes
No dependencies, no models. Via ComfyUI Manager search "RF Nodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/foxtrot-roger/comfyui-rf-nodes
Restart ComfyUI; it's under RF in the menu.
Common issues
- "It returned the wrong line." - Zero-based indexing: the first line is index 0, not 1. Off-by-one is the classic mistake.
- "I wanted a random prompt." - This node is deterministic; it picks what the index says. For randomness, feed it a value that changes per run (seed-derived), or look for an explicit random node.
- "Looks like RF_OptionsString." - They're siblings. OptionsString does the same split-and-select on a plain text input; this one additionally declares list-mode input. Pick whichever matches your graph's typing.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| lines | STRING | — | |
| index | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |