Nodes/MoonNe_Nodes/Batch Conditional Text
ComfyUI Node

Batch Conditional Text

Show Text Only on Frames 25–40 (and Roll the Dice While You're At It)

By Moon-NE·Created 2 months ago·Updated 2 months ago· 0
Batch Conditional Text
    • STRING
    batch_index0
    text
    greater_than0
    less_than999
    probability1.00
    seed0

    The problem: text that should only exist on some frames

    You're animating, or generating a batch, and you want the prompt to change mid-run - say, "closeup, dramatic lighting" only while frames 25–40 are cooking, and nothing special elsewhere. You could hand-edit the prompt for every frame like it's 1999. Or you could drop in a node that reads the current frame's index and decides for itself.

    Batch Conditional Text is that node. It lives in Moon-NE's MoonNe_Nodes pack, a small collection of "random generator" utilities for lazy prompt management, and it does one clean thing: given the current batch index, it outputs your text when the index falls in a range you define - and outputs an empty string otherwise. Optional probability adds a roll of the dice on top.

    How the range logic works

    The node takes greater_than and less_than and compares them to decide what mode it's in. It's simple but worth knowing, because the mode changes the meaning:

    • greater_than < less_thaninside range: text fires when greater_than <= index <= less_than.
    • greater_than > less_thanoutside range: text fires when the index is below less_than OR above greater_than. Great for "everything except this middle chunk."
    • greater_than == less_thansingle point: fires only when the index equals that exact value.

    So with greater_than: 40, less_than: 25 you get text on every frame except 25 through 40 - the "outside" mode is the pack README's own example and it's the least obvious one, so don't be surprised when flipping the values flips the meaning.

    The default probability: 1.0 means always fire when in range. Drop it to 0.3 and only 30% of qualifying frames get the text.

    Determinism, the good kind

    Here's the part that's easy to get wrong and hard to love until you see it: the node seeds its randomness with f"{seed}_{batch_index}". That means each frame index gets its own deterministic draw - frame 27 with seed 1234 always rolls the same result, which is exactly what you want when you're debugging or re-rendering. It also means the random decision is per frame, not per run: with a 30% probability, different frames roll different ways rather than the whole batch flipping a single coin.

    Two gotchas fall out of this:

    1. The batch_index has to actually vary. ComfyUI does not auto-increment an index as it churns through a batch - you have to feed this input from whatever is stepping your frames (a counter node, an animation loop, a batch-of-images iterator). Feed it a constant 0 and every frame is "frame 0," so the node fires on all of them or none of them.
    2. Every run re-rolls. The node overrides IS_CHANGED to return NaN, the classic ComfyUI cache-busting trick, so the probability is re-evaluated on each execution instead of being frozen by the cache. That's the "cache busting" the README brags about, and it's the behavior you want here - a stale conditional is a useless one.

    Inputs and output

    • batch_index (INT) - the current frame/batch index, from your loop or counter.
    • text (STRING, multiline) - the text to emit when conditions are met.
    • greater_than, less_than (INT) - the range-defining pair described above.
    • probability (FLOAT, 0–1) - chance to fire per frame.
    • seed (INT) - base seed for the per-frame random draw.

    Output is a single STRING: your text, or "" when it doesn't fire. An empty string into a CLIP Text Encode just contributes nothing, so you can safely chain it into prompt assembly - which is the intended pattern.

    Install

    The whole pack installs the same way, no dependencies and no model downloads (the README's total install advice is "just plug it into your workflow"):

    cd ComfyUI/custom_nodes
    git clone https://github.com/Moon-NE/MoonNe_Nodes
    

    Restart ComfyUI afterward - or, easier, use ComfyUI Manager and search for MoonNe_Nodes. If you're building a video prompt workflow and keep reaching for the manual, this is the node that makes per-frame prompt control feel like a checkbox instead of a chore.

    CategoryText/Conditional

    Inputs (6)

    NameTypeDefaultDescription
    batch_indexINT00–999999
    textSTRING
    greater_thanINT0
    less_thanINT999
    probabilityFLOAT1.000–1
    seedINT00–18446744073709550000

    Outputs (1)

    NameTypeDescription
    STRINGSTRING