重置/重复索引
Wrap and recycle loop counters without the modulo headache
- index
Loop counters are where ComfyUI workflows go to die. You're iterating a batch, the counter marches upward forever, and either you overflow a batch size or the same few prompts get skipped. This node is the counter-tamer: it takes a running index and two behaviors - reset wraps it back around when it hits a step size, repeat counts how many times it's cycled. The pack's README describes it as built for the easyuse plugin's for-loop index, but it works with any loop structure that hands you an incrementing integer.
The math, concretely. In reset mode, with step set to 3: index 0,1,2 map to 0,1,2, then index 3 wraps back to 0, 4→1, 5→2, and so on - a modulo. In repeat mode, with step 3: 0,1,2 → 0, 3,4,5 → 1, 6,7,8 → 2 - that's integer division, telling you which cycle you're on. Either way, the start value gets added on top, so start=1 shifts everything up by one. The two tooltips spell it out: start is where the index begins (0 disables it), step is where reset/repeat kicks in (0 disables it).
The inputs: index (INT, required) and the optional start (INT, default 0), step (INT, default 0), and mode (dropdown: reset or repeat). Output: a single index (INT).
Why does this matter in practice? The canonical use is pairing with the pack's "提示词逐行读取" (Prompt Line Reader): you have 5 prompts in a file and want to generate images cycling through all 5 repeatedly. Feed the raw loop counter in with step=5, mode=reset, and the output index stays in 0..4 forever - no out-of-range errors, no skipped prompts. Flip to repeat and you get a "which cycle am I on" number you can use to vary other parameters per pass, like denoise strength drifting across iterations.
Install: part of ComfyUI-My-Nodes - ComfyUI Manager → search "ComfyUI-My-Nodes", or git clone https://github.com/Tagbliton/ComfyUI-My-Nodes into custom_nodes and restart. Local utility: no API key, no network.
Gotchas. step=0 means "feature disabled" - if you set step to 0 expecting an infinite wrap, you get the raw index back, and the tooltip warns you exactly about this. Negative start values are clamped to 0 by the widget, so you can't offset backwards. And the mode names are easy to mix up on first contact: reset wraps within the range (modulo), repeat counts the cycles (division). One look at the math above and you'll never mix them again.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| index | INT | — | |
| startopt | INT | 0 | index从start起始,0表示不启用 |
| stepopt | INT | 0 | 当index迭代次数等于step时重置/index重复次数等于step,0表示不启用 |
| modeopt | COMBO | 2 options: reset, repeat |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| index | INT | — |