Logic compare tool showing error for non numeric values

46 views
Skip to first unread message

Vivek

unread,
May 15, 2018, 9:05:23 AM5/15/18
to Blockly
Hello all

I am using logic compare as code is provided below. Problem is that when iam inserting text in the blank space in logic compare block then it is showing error in console as :-
You can find error in image attached


code is as following for Logic compare block.
Block file:-
/block/logic.js

{
    "type": "logic_compare",
    "message0": "%1 %2 %3",
    "args0": [
      {
        "type": "input_value",
        "name": "A"
      },
      {
        "type": "field_dropdown",
        "name": "OP",
        "options": [
          ["=", "EQ"],
          ["\u2260", "NEQ"],
          ["<", "LT"],
          ["\u2264", "LTE"],
          [">", "GT"],
          ["\u2265", "GTE"]
        ]
      },
      {
        "type": "input_value",
        "name": "B"
      }
    ],
    "inputsInline": true,
    "output": "Boolean",
    "colour": "%{BKY_LOGIC_HUE}",
    "helpUrl": "%{BKY_LOGIC_COMPARE_HELPURL}",
    "extensions": ["logic_compare", "logic_op_tooltip"]
  }


Code in generator file:-
Blockly.C['logic_compare'] = function(block) {
  // Comparison operator.
  var OPERATORS = {
    'EQ': '==',
    'NEQ': '!=',
    'LT': '<',
    'LTE': '<=',
    'GT': '>',
    'GTE': '>='
  };
  var operator = OPERATORS[block.getFieldValue('OP')];
  
  var order = (operator == '==' || operator == '!=') ?
      Blockly.C.ORDER_EQUALITY : Blockly.C.ORDER_RELATIONAL;
  
  var argument0 = Blockly.C.valueToCode(block, 'A', Blockly.C.ORDER_NONE);
  var argument1 = Blockly.C.valueToCode(block, 'B', Blockly.C.ORDER_NONE);
 
  var code = argument0 + ' ' + operator + ' ' + argument1;
  return [code, Blockly.C.ORDER_NONE];
};
Untitled.png

Rachel Fenichel

unread,
May 16, 2018, 5:17:30 PM5/16/18
to Blockly
Thanks for including the block definition and generator for the 'logic_compare' block.

What is the 'pin' block?  The error message says "Expecting tuple from value block "pin"", so it looks like the error is in the generator for a different block.

Rachel
Reply all
Reply to author
Forward
0 new messages