node.script doesn't receive the number zero 0 (Fixed in Max 8.1.2)

Dimitri Aatos's icon

Hi all,
I'm trying to make a node script that will receive numbers from Max as input, I added a handler (Max.addHandler()) with Max.MESSAGE_TYPES.NUMBER as the first argument and I'm printing everything it receives to the Max console. It works fine except for 0. The handler doesn't get triggered. Is that expected behaviour? Is there a way to detect if a 0 is sent to a node.script?

// This is the content of zero.js
const Max = require('max-api')
Max.addHandler(Max.MESSAGE_TYPES.NUMBER, (number) => {
  Max.post("Number " + number)
})
Max Patch
Copy patch and select New From Clipboard in Max.

Dimitri Aatos's icon

I posted about the issue to the Max/MSP facebook group and people suggested that it's a bug so I did a bug report.

Bjorn Vayner's icon

Could it be that the 0 is seen as a false boolean?
This article might clear it up: https://codeburst.io/javascript-double-equals-vs-triple-equals-61d4ce5a121a

Dimitri Aatos's icon

It sounds probable, I got a reply to my bug report that suggested that as well. Unfortunately 0 is the only falsy value that can be sent from max to node, so we can't do much checking as regular users.

Dimitri Aatos's icon

This behaviour was caused by a bug that was fixed in Max 8.1.2.
Max 8.1.2 Release Notes list it under Fixed Bugs as node.script: number 0 (zero) triggers proper handler
http://cycling74.s3.amazonaws.com/support/version_8_1_2.html