M String Pick (index)
Picking a line out of a list — the boring node you'll actually reuse
- text
M String Pick (index) is the simplest node in the ComfyUiNodes pack, and the one you'll actually keep reaching for. It takes a multiline list of strings and an integer, and hands back the line at that index. One string in, one string out, nothing else to tune. That's the entire job.
The use case: any time a choice should be driven by a number that isn't a seed. The integer can come from anywhere - a slider, the pack's own math nodes, a counter, another node's INT output. So you can keep a small catalog of prompts, style labels, filenames, or LoRA names in the multiline box and select between them programmatically instead of hand-editing a text field. Wire the output into a CLIP Text Encode, a filename template, or anything else that eats a STRING.
How it works
Under the hood it's exactly as direct as it looks: the lines input is split on newlines, blank and whitespace-only lines are dropped, and arr[idx] comes out the text socket. Two behaviors to internalize:
- Negative indices return an empty string. It does not do Python-style negative indexing -
-1isn't "last line," it's just nothing. If you're coming from Python, this is the one thing that'll bite you. - Out-of-range returns an empty string too, silently, rather than erroring the graph. Same for an all-blank list.
Because blank lines are filtered out before indexing, a trailing newline or extra blank row won't shift your indices - but it also means your index counts non-blank lines only, so edit carefully if your catalog has gaps.
Inputs and output
- idx - the line number, an INT, default 0 (first line).
- lines - the catalog, multiline, default
a\nb\ncso it works out of the box. - text - the picked line, or
""if the index is out of range.
That's the whole API. There's no seed involved, no hashing, no randomness - same idx, same line, every time. If you want seed-driven variation instead of index-driven selection, that's what the pack's other string node (M Regex Replace, picked option) is for.
Installing it
It ships in the ComfyUiNodes pack. ComfyUI Manager is easiest - search "ComfyUiNodes" and install - or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/Madlumi/ComfyUiNodes
# restart ComfyUI
No requirements.txt, no model files, pure stdlib. It's about as low-risk an install as custom nodes get.
When it lets you down
There's basically one failure mode: empty output because idx fell outside the list. It fails quietly, so if you're feeding the result somewhere important (a filename, a prompt) and you get a blank, check the index range and that you didn't index past a block of blank lines. Everything else is hard to get wrong - which, for a plumbing node in this ecosystem, is a feature.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| idx | INT | 0-2147483648–2147483647 | — |
| lines | STRING | a b c | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |