Create Variable button in drop-down alongside new button

249 views
Skip to first unread message

Austin Bart

unread,
Jan 2, 2017, 10:45:34 AM1/2/17
to Blockly
Hi, we're experimenting with adopting the new version of Blockly that includes the new button for creating variables. However, I wanted to have the old mechanism for creating variables available too, where you could Create a Variable from the variable dropdown. I figured this would ease adoption for our course staff.

In core/field_variable.js, on line 191, inside Blockly.FieldVariable.prototype.onItemSelected, I added the following to the dispatcher:

   } else if (this.newVarItemIndex_ >= 0 &&
               menu.getChildAt(this.newVarItemIndex_) == menuItem) {
      var set_value = this.set_value;
      Blockly.Variables.createVariable(workspace, function(new_name) {
          if (new_name !== null && new_name !== undefined) {
              set_value(new_name);
          }
      });
      
      return;
   }

I figured something like this would work, and although it did create the variable, it didn't update auto-select that variable in the drop-down or even update the UI to include the new element. Instead, it just checked the menu item for Creating Variables. Any tips on how to have this functionality available again? I'm a little strapped for time before the semester starts, or I wouldn't bother you guys.



Happy new year,
~Cory

Rachel Fenichel

unread,
Jan 3, 2017, 2:23:03 PM1/3/17
to Blockly
Hi Cory,

set_value isn't a function.  You probably mean 
var set_value = this.setValue;

If that doesn't fix it, calling render() on the block may help.

Cheers,
Rachel

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Austin Bart

unread,
Jan 15, 2017, 10:55:55 AM1/15/17
to Blockly
Wow, that was a silly mistake. Thanks so much for the help and the excellent catch. Things work completely as expected.

~Cory
Reply all
Reply to author
Forward
0 new messages