In Blockly, not all of the blocks associated with a category are necessarily found within the named category file. Such is the case here.
A good way to figure out which file and function to look at is by heading over to Blockly demos - code editor which lets you export blocks as XML. Drag the block you're interested in examining the generator source for into the workspace, in this case it's the "variable -- change by" block, then export to XML:
<xml xmlns="https://developers.google.com/blockly/xml">
<variables>
<variable id="F;)U+)(_^:3!Z~mxvyWO">asd</variable>
</variables>
<block type="math_change" id="xXz{jIXrbvaz9DcE*7O6" x="338" y="88">
<field name="VAR" id="F;)U+)(_^:3!Z~mxvyWO">asd</field>
<value name="DELTA">
<shadow type="math_number" id="d5W].A}ldwUj2~+0PKnj">
<field name="NUM">1</field>
</shadow>
</value>
</block>
</xml>
This shows block type="math_change"
, so we follow the math_
prefix to blockly/generators/javascript/math.js
instead of variables.js
:
blockly.javascript['math_change'] = function(block) {
// add to a variable in place.
var argument0 = blockly.javascript.valuetocode(block, 'delta',
blockly.javascript.order_addition) || '0';
var varname = blockly.javascript.variabledb_.getname(
block.getfieldvalue('var'), blockly.variable_category_name);
return varname + ' = (typeof ' + varname + ' == \'number\' ? ' + varname +
' : 0) + ' + argument0 + ';\n';
};
Add this function to your script to override the existing implementation and replace it with your desired logic.