carlosperate / ardublockly

Visual programming for Arduino. Based on blockly, implements Arduino code generation and facilitates program uploading.
http://ardublockly.embeddedlog.com
Apache License 2.0
449 stars 277 forks source link

Conditional statement containing function does not work #215

Open arpicheck opened 5 years ago

arpicheck commented 5 years ago

You can not formulate the following expression, but there is a workaround:

image

fraser125 commented 3 years ago

The original Blockly implementation is in Javascript which just uses one general purpose number type so this works fine for JavaScript. The Arduino uses C which has many more numeric types and is much stricter about their usage. Some of the other functions available in the DropDown list such as log may return a decimal value so by default this block returns a decimal because it would be the most accurate. When the logic_compare block checks that the condition is valid it considers DECIMAL compared to SCALAR to be invalid and rejects the comparison as shown in the first example.

The second example probably does an internal conversion of 10 to 10.0 and avoids the type check.

A couple of possible fixes (probably more)

  1. Change the logic_compare block to accept a decimal and scalar comparison
  2. Break the math_single block into 2, one that works only with operations that only have scalar results and another that does operations that may return decimal results.
  3. Force the other numeric value to be decimal by default. (probably would perform poorly on Arduino, using floats when they aren't really needed).