{"record":{"id":"3c06ff699687e02f","repo":"BabylonJS/Babylon.js","slug":"cannot-compare-a-and-b","errorCode":null,"errorMessage":"Cannot compare ${a} and ${b}","messagePattern":"Cannot compare (.+?) and (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.ts","lineNumber":790,"sourceCode":"        if (_AreSameVectorOrQuaternionClass(aClassName, bClassName) || _AreSameMatrixClass(aClassName, bClassName) || _AreSameIntegerClass(aClassName, bClassName)) {\r\n            return (a as Vector3).equals(b as Vector3);\r\n        }\r\n        // Handle mixed number/FlowGraphInteger comparison\r\n        if (isNumeric(a) && isNumeric(b)) {\r\n            return getNumericValue(a as FlowGraphNumber) === getNumericValue(b as FlowGraphNumber);\r\n        }\r\n        if (typeof a !== typeof b) {\r\n            return false;\r\n        }\r\n        return a === b;\r\n    }\r\n}\r\n\r\nfunction ComparisonOperators(a: FlowGraphNumber, b: FlowGraphNumber, op: (a: number, b: number) => boolean) {\r\n    if (isNumeric(a) && isNumeric(b)) {\r\n        return op(getNumericValue(a), getNumericValue(b));\r\n    } else {\r\n        throw new Error(`Cannot compare ${a} and ${b}`);\r\n    }\r\n}\r\n\r\n/**\r\n * Less than block.\r\n */\r\nexport class FlowGraphLessThanBlock extends FlowGraphBinaryOperationBlock<FlowGraphNumber, FlowGraphNumber, boolean> {\r\n    constructor(config?: IFlowGraphBlockConfiguration) {\r\n        super(RichTypeAny, RichTypeAny, RichTypeBoolean, (a, b) => this._polymorphicLessThan(a, b), FlowGraphBlockNames.LessThan, config);\r\n    }\r\n\r\n    private _polymorphicLessThan(a: FlowGraphNumber, b: FlowGraphNumber) {\r\n        return ComparisonOperators(a, b, (a, b) => a < b);\r\n    }\r\n}\r\n\r\n/**\r\n * Less than or equal block.\r","sourceCodeStart":772,"sourceCodeEnd":808,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.ts#L772-L808","documentation":"ComparisonOperators is the shared implementation behind the comparison flow-graph blocks (<, <=, >, >=, ==, etc.). It only supports operands that pass isNumeric() — plain numbers or FlowGraphInteger values. If either operand is a boolean, string, vector, or any other FlowGraphTypes value, it throws 'Cannot compare ...' rather than guessing an ordering. Note FlowGraphEqualityBlock (==) reuses this helper, so equality checks on non-numeric values also throw.","triggerScenarios":"Connecting a non-numeric output (boolean from a logic block, a string, or a Vector3/Quaternion) into either input of a comparison block (less-than, greater-than, equality, etc.) and executing the flow graph.","commonSituations":"Comparing a boolean result of a logical AND block with a number; accidentally wiring a vector output into a comparison block; comparing strings expecting lexicographic order which the block does not support.","solutions":["Ensure both comparison inputs are numeric: insert extraction blocks (e.g. vector x/y/z extract) to compare components, or convert the value with Number(...) before it reaches the block.","If you intended equality on non-numeric values, implement a custom flow graph block or compare via dedicated blocks instead of reusing the numeric comparison block.","Check upstream block types in the graph editor and correct the mis-wired connection feeding the comparison block."],"exampleFix":"// before: comparing a boolean and a number\nconst cmp = new FlowGraphLessThanBlock();\ncmp.a.connect(logicBlock.output); // boolean -> throws\n\n// after: extract a numeric value or coerce first\nconst cmp = new FlowGraphLessThanBlock();\ncmp.a.connect(Number(...)); // number\n// or compare vector components:\ncmp.a.connect(vecExtractBlock.x);","handlingStrategy":"type-guard","validationCode":"// before the comparison block executes\nfunction numericOperands(a, b) {\n  const ok = (v) => typeof v === 'number' || (typeof v === 'object' && v !== null && 'value' in v);\n  return ok(a) && ok(b);\n}\nif (!numericOperands(cmpInputA, cmpInputB)) throw new TypeError('Comparison inputs must be numeric');","typeGuard":"function isNumericValue(v): v is number | FlowGraphInteger {\n  return typeof v === 'number' || (typeof v === 'object' && v !== null && 'value' in v && typeof (v as any).value === 'number');\n}","tryCatchPattern":"try {\n  result = comparisonBlock.evaluate(context);\n} catch (e) {\n  if (e.message.startsWith('Cannot compare')) {\n    // inspect and coerce inputs to numbers, then retry\n    result = Number(a) < Number(b);\n  } else { throw e; }\n}","preventionTips":["Never wire boolean/string/vector outputs into comparison blocks; decompose vectors into components first.","Use the graph editor's port type highlighting to verify connection compatibility before running.","For equality of non-numeric values, write a custom block rather than reusing the numeric comparison."],"tags":["babylonjs","flow-graph","comparison","type-mismatch"],"backgroundTag":"non-numeric-operand","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}