Iter_TextSwitch
Iter_TextSwitch turns prompt choice into a number
- STRING
If you've ever built a workflow where you hand-edit a text node, hit queue, edit it again, queue again, this node is the fix you didn't know you wanted. Iter_TextSwitch is a string switch from the ComfyUI-IterSwitch pack. You wire a stack of prompt strings into it, and it hands exactly one of them to whatever comes next, chosen by an integer. That sounds trivial until you realize what it unlocks: "which prompt do I use" becomes a number, and numbers can be driven by other nodes.
What it does
You get up to 128 text inputs, a base add_text string, and one STRING output. The node returns add_text + <the selected slot> - so it's a string switcher and a tiny concatenator. Want masterpiece, best quality, in front of every variant? Drop it in add_text and connect the variants to slots. That's the cleanest prompt-combinator pattern, and it's why the author filed this one under Logic rather than the pack's other Iterators.
Where it shines is iteration. Drive output_index from a counter or seed node and run one queue, and you step through every variant in a single pass. A/B testing ten prompt variants stops being ten hand-edits and becomes one queue run.
How it works
The three controls are output_index, input_count, and use_last_input. input_count is the magical one: the pack ships a little web extension that watches it, and dragging it up physically grows the node with new sockets named text_0, text_1, and so on. Drag it back down and the extra sockets get trimmed from the end - existing connections survive. Under the hood the Python picks output_index % input_count (so an out-of-range index silently wraps around), then, if use_last_input is on, walks backward toward text_0 to find the nearest connected slot.
That fallback is the difference between "give me slot 4" and "give me slot 4, or the nearest connected slot below it." Turn it on and a mid-stack disconnect won't kill the run.
Wiring it up
add_text- base string prepended to everything. You can type in it or wire another string into it.output_index- which slot to pick. Wire this from a counter node to iterate.input_count- how many sockets exist. Set this first; the sockets appear as you raise it.use_last_input- default off. On, it falls back to the nearest connected lower slot.
The STRING output feeds anything that takes text: a CLIPTextEncode for the positive prompt, a Save Text node, or another string consumer. Since ComfyUI now treats text as a first-class wire type, this slots straight in.
Installing the pack
Same story for all six nodes in ComfyUI-IterSwitch - no dependencies, no model downloads. There's no requirements.txt at all, so a bare git clone is the whole install:
cd ComfyUI/custom_nodes
git clone https://github.com/younger15/ComfyUI-IterSwitch.git
Then restart ComfyUI (or hit refresh on the browser) so the web extension loads. ComfyUI Manager works too if you prefer: search "ComfyUI-IterSwitch," and if the registry search comes up empty - this is a small pack - use Manager's install-by-Git-URL option with the same link.
Common issues
- Text node crashes with a TypeError. The return is literally
add_text + selected. Ifuse_last_inputis off and you point at an unconnected slot,selectedisNone, andstr + Noneblows up. Keep fallback on with a wired slot below your index, or only point at sockets you've actually connected. It's the one sharp edge in the whole pack, and it's real - the shipped code does exactly this. - Sockets don't appear. The dynamic inputs are JavaScript, not Python. If you only reloaded the backend, the sockets won't show. Restart ComfyUI fully, or refresh the page.
- Index wraps.
output_index5 with three inputs silently gives you slot 2 thanks to the modulo. That's a feature for looping, a trap when you expect an error.
One honest note: this pack has essentially no community footprint yet - none of its nodes show up in searches or search-console data. If you hit something weird, you're probably the first to find it. Check the GitHub issues and file one if it's genuinely broken.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| add_text | STRING | — | |
| output_index | INT | 00–18446744073709550000 | — |
| input_count | INT | 21–128 | — |
| use_last_input | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |