ComfyUI Node

ChooseInt

The type-safe two-way switch for integers — ChooseInt picks a or b from a boolean

By rabanti-github·Created 2 months ago·Updated 6 days ago· 0
ChooseInt
    • INT
    conditionfalse
    a0
    b0

    If you've ever wanted a workflow that picks between two numbers based on some condition, you're about to meet the simplest node that does it. ChooseInt is a two-way switch for integers: a boolean condition in, one of two integer values out. True gives you a, false gives you b. That's the entire spec - there's no op dropdown, no hidden mode, nothing else. a if condition else b in Python, exposed as a node.

    That simplicity is the selling point, honestly. In the plumbing layer of ComfyUI - the giant population of value, switch, and logic nodes that carry data around without ever touching a pixel - this is the "A/B switch" shape. The useful trick it does well is staying typed: it's an INT socket in, INT out, so the graph stays readable and the type-checker stays happy. Compare that to the ANY-typed switches like rgthree's Any Switch, which erase types to gain flexibility. ChooseInt gives up nothing and just does the one thing.

    How you actually use it

    The magic is in what feeds the condition socket, because that's what turns a manual toggle into a real decision. Wire in a boolean from a comparison node - ComfyMath has IntBinaryCondition (Eq, Gt, Lt, and friends) and IntUnaryCondition (IsPositive, IsEven, and so on) - and now the choice happens automatically. Classic example: seed selection. Feed condition from a "use fixed seed?" toggle or a comparison, a as your favorite seed, b as a random one, and the output plugs into the KSampler's seed socket. Or pick a batch size based on whether you're in a "quick preview" mode. Or a step count based on some test.

    One trap worth naming: condition is a real BOOLEAN socket, not a 0/1 integer. You can't feed a plain INT into it and expect it to just work - run it through ComfyMath's IntToBool first (which treats any non-zero, including negatives, as true). Getting that wrong is the most common first stumble.

    Inputs and output

    • condition - BOOLEAN, defaults to false. The selector.
    • a - INT, default 0. Returned when condition is true.
    • b - INT, default 0. Returned when condition is false.

    Output is a single INT. That's it.

    Installing it

    ChooseInt is part of ComfyMath (published as ComfyMath-NG). Install via ComfyUI Manager - search "ComfyMath" - or clone:

    cd ComfyUI/custom_nodes
    git clone https://github.com/rabanti-github/ComfyMath.git ComfyMath-NG
    

    Restart ComfyUI. Note that this fork registers the same node IDs as the original ComfyMath, so disable or remove the original first or the two collide. Dependencies are just numpy - no models, no downloads, nothing heavy.

    When to reach for it

    It's not exciting, and it shouldn't be. ChooseInt is the kind of node you add once, wire once, and stop noticing - which is exactly what you want from control logic. When your workflow starts accumulating "if this then that" decisions, this is the cleanest possible way to make one of them for an integer.

    Categorymath/control

    Inputs (3)

    NameTypeDefaultDescription
    conditionBOOLEANfalse
    aINT0
    bINT0

    Outputs (1)

    NameTypeDescription
    INTINT