#10483·blockly

0 not taken in account

Author: ascazzolaCreated Aug 20, 2021Updated Sep 11, 2026
Labelshelp wantedarea: docs & examples

on https://blocklycodelabs.dev/codelabs/custom-generator/index.html?index=..%2F..index#6

The array block generator example does not take in account the value 0 for integers. The example code is: const values = []; for (var i = 0; i < block.itemCount_; i++) { let valueCode = codelabGenerator.valueToCode(block, 'ADD' + i, codelabGenerator.PRECEDENCE); if (valueCode) { values.push(valueCode); } }

and mentions that null values are not taken in account but 0 return false on the if and is not taken in account too.

I replaced it with values.push([undefined, null, ""].indexOf(valueCode) > -1 ? 'null' : valueCode);

But still not working to 0. I debugged a bit the code and the file generator.js on line 259 has the next code

if (!code) { return ''; }

I think here appear the same issue, but this is inside the library code, do you have any workaround to create my custom code generator fixing it, or am I doing / understanding something wrong?

Source: RaspberryPiFoundation/blockly