Nodes/ComfyUI-JDCN/LogicUtil_ReturnAorBValue
ComfyUI Node

LogicUtil_ReturnAorBValue

The ternary in node form — LogicUtil_ReturnAorBValue

By daxcay·Created 2 years ago·Updated about a year ago· 159
LogicUtil_ReturnAorBValue
  • condition
  • input1
  • input2
  • *

The one-line version

LogicUtil_ReturnAorBValue is a if condition then A else B - in node form. Give it a condition, a value A, and a value B, and it passes through A when the condition is truthy, B otherwise. It's the closest thing in this pack to a generic "switch," and it accepts any type on both value sockets, so you can route numbers, strings, seeds, or even bigger objects through it.

It comes from the LogicUtil family inside ComfyUI-JDCN, the pack best known for its folder and file tools. LogicUtil is the logic section, credited to aria1th's ComfyUI-LogicUtils in the source.

How it works

Plain Python ternary, nothing hidden:

return (input1 if condition else input2,)

The condition is also a wildcard socket, so anything that's "truthy" counts as True - a True boolean, a nonzero number, a non-empty string. That's convenient and a little dangerous: 0 and "" are falsy, so numeric conditions behave like "is it nonzero?"

Inputs and outputs

  • condition (*) - what decides the choice; truthy → input1, falsy → input2
  • input1 (*) - returned when condition is True
  • input2 (*) - returned when condition is False
  • Output: * - whichever of the two inputs won, same type as the inputs

The output socket is wildcard, which means ComfyUI lets you wire it anywhere - the type it actually carries at runtime is whatever came in. Keep both value inputs the same type or your downstream node will get a surprise.

Installing it

Standard pack install:

Easiest - ComfyUI Manager → Install Custom Node → search ComfyUI-JDCN → install → restart.

Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/daxcay/ComfyUI-JDCN.git
cd ComfyUI-JDCN
pip install -r requirements.txt

Restart ComfyUI. Only dependency is piexif; no models to download.

Common issues

  • Truthiness, not strict True. A condition of 2 or "yes" is True; 0, "", and None are False. If your condition is a number, "nonzero" is what you're actually testing.
  • Mixed types down the line. The wildcard output hides the type until runtime. If input1 is an INT and input2 is a STRING, whichever wins is what your downstream gets - and ComfyUI might not type-check it until the queue runs. Keep them the same type.
  • There's no "if both are True" logic here. It's a selector, not a gate. If you want a boolean result from two conditions, use the compare/gate nodes in the same pack.

When you'd actually reach for it

Every time you need conditional wiring - and in ComfyUI, that's a lot. "Use this seed when the checkbox is on, that seed when it's off." "Pick prompt A or prompt B." "Choose this upscaler or that one based on a comparison." Pair it with LogicUtil_ABiggerThanB or LogicUtil_AContainsB(String) to build the condition, and you've got real branching in your graph.

CategoryLogicUtil

Inputs (3)

NameTypeDefaultDescription
condition*0
input1*
input2*

Outputs (1)

NameTypeDescription
**