Nodes/ComfyUI Assistant Node/PVL Math Condition
ComfyUI Node

PVL Math Condition

Math that picks its own branch

By pvlprk·Created about a year ago·Updated 8 months ago· 1
PVL Math Condition
  • evaluate
  • a
  • b
  • c
  • d
  • INT
  • FLOAT
on_true
on_false

PVL Math Condition is the sibling of PVL Math with one extra superpower: it can compute different formulas depending on a flag. You give it a condition, an expression for when the condition is true, an expression for when it's false, and it evaluates exactly one of them. That turns a dull "do math" node into something that can drive behavior changes in a workflow - the difference between "if the flag is set, use 40 steps, otherwise 20" and building two separate branches that never talk to each other.

It ships in pvlprk/comfyui-pvl-api-nodes ("ComfyUI Assistant Node"), and like PVL Math it's a clone of the essentials family's simple math nodes - same safe-expression machinery, same INT/FLOAT outputs.

How it works

Three moving parts:

  • evaluate - the condition. It's a wildcard input, so it'll accept a boolean, a number, or really anything. Truthiness is generous: nonzero numbers are true, 0 is false, strings are truthy if non-empty, lists are truthy if non-empty. Plug a BOOLEAN from a switch or condition node and you're set.
  • on_true / on_false - two expression strings, same syntax as PVL Math (+ - * / // % **, unary minus, parentheses). Only the one matching the condition is evaluated, so you can even put a 1 / 0 in the branch you're not using and nothing blows up.
  • a, b, c, d - optional wildcard values the expressions can reference. Note this node gives you a fourth variable that plain PVL Math doesn't.

The safe evaluator rejects anything outside the whitelist - no function calls, no subscripts here - and on a bad parse it returns 0.0 rather than crashing. Same silent-failure trait as its sibling, so keep an eye on expressions that "should" work but keep zeroing.

Outputs are INT and FLOAT, both from whichever expression won.

The obvious use case

The canonical pattern: a boolean that some upstream node (an API response, a seeded random, a UI toggle) flips, and you want a number to follow it. Instead of:

  • steps = 40 when "high quality" is on, else 20
  • CFG = 7 when "creative" is on, else 4
  • width = 1024 when "portrait mode" is on, else 768

...you write the two expressions once and let the condition pick. Feed the FLOAT into a sampler's cfg, or the INT into steps, and you've made a one-wire parameter switch out of what would otherwise be a mess of condition nodes.

Installing

cd ComfyUI/custom_nodes
git clone https://github.com/pvlprk/comfyui-pvl-api-nodes

restart, or install through ComfyUI Manager by searching for "ComfyUI Assistant Node". No models, no dependencies beyond what ComfyUI ships. The pack's requirements.txt installs a lot of unrelated API-client libraries, but none of them matter for this node.

Where it stumbles

Keep the expressions in the arithmetic + parentheses subset. The moment you reach for a function or a subscript that PVL Math would allow, this node refuses - the whitelist is deliberately narrower. If you're chaining math nodes downstream, also remember the output is a raw number, not a string, so a converter back to text is on you if that's what the next node wants.

Categoryessentials_mb/utilities

Inputs (7)

NameTypeDefaultDescription
evaluate*0
on_trueSTRING
on_falseSTRING
aopt*0
bopt*0
copt*0
dopt*0

Outputs (2)

NameTypeDescription
INTINT
FLOATFLOAT