Skip to content

Commit

Permalink
Fixing for loop block
Browse files Browse the repository at this point in the history
Adding implementation to update variable name on for loop block.
  • Loading branch information
kozbial committed Aug 17, 2016
1 parent 2f82279 commit 8e6578a
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 0 additions & 1 deletion appengine/genetics/js/cage.js
Original file line number Diff line number Diff line change
@@ -171,7 +171,6 @@ Genetics.Cage.doneCallback_ = null;
* Stop and reset the cage.
*/
Genetics.Cage.reset = function() {
clearTimeout(Genetics.Cage.pid);
Genetics.Cage.EVENTS.length = 0;
Genetics.Cage.aliveMice_.length = 0;
Genetics.Cage.miceMap_ = {};
5 changes: 0 additions & 5 deletions appengine/genetics/template.soy
Original file line number Diff line number Diff line change
@@ -156,11 +156,6 @@
</value>
</shadow>
</value>
<value name="BY">
<shadow type="math_number">
<field name="NUM">1</field>
</shadow>
</value>
</block>
<block type="controls_flow_statements"></block>
</category>
24 changes: 22 additions & 2 deletions appengine/js/js-blocks.js
Original file line number Diff line number Diff line change
@@ -197,13 +197,13 @@ Blockly.Blocks['controls_whileUntil'].init = function() {
};

/**
* Block for 'for' loop.
* Initialization for 'for' loop Block.
* @this Blockly.Block
*/
Blockly.Blocks['controls_for'].init = function() {
this.jsonInit({
// TODO(kozbial) Set "?" to %1 variable name.
"message0": "for (%1 = %2; ? < %3; ? += 1) { %4 %5 }",
"message0": "for (%1 = %2; %3 < %4; %5 += 1) { %6 %7 }",
"args0": [
{
"type": "field_variable",
@@ -216,12 +216,22 @@ Blockly.Blocks['controls_for'].init = function() {
"check": "Number",
"align": "RIGHT"
},
{
"type": "field_label",
"name": "VAR1",
"text": '?'
},
{
"type": "input_value",
"name": "TO",
"check": "Number",
"align": "RIGHT"
},
{
"type": "field_label",
"name": "VAR2",
"text": "?"
},
{
"type": "input_dummy"
},
@@ -246,6 +256,16 @@ Blockly.Blocks['controls_for'].init = function() {
});
};

/**
* E for 'for' loop.
* @this Blockly.Block
*/
Blockly.Blocks['controls_for'].onchange = function(e) {
var varName = this.getFieldValue('VAR');
this.setFieldValue(varName, 'VAR1');
this.setFieldValue(varName, 'VAR2');
};

Blockly.JavaScript['controls_for'] = function(block) {
// For loop.
var variable = Blockly.JavaScript.variableDB_.getName(

0 comments on commit 8e6578a

Please sign in to comment.