forked from google/blockly
-
Notifications
You must be signed in to change notification settings - Fork 6
Useful Code Information
MaryS94 edited this page Jun 1, 2016
·
8 revisions
To return the block SVG which displays all of the information about the block:
console.log(Blockly.selected);
To access specific information to alter or reference:
var test = Blockly.selected.type;
To get information about the workspace:
console.log(Blockly.mainWorkspace);
Note that Blockly.mainWorkspace can be used to call useful functions found in ../core/workspace.js and ../core/workspace_svg.js
//Check if the workspace is empty
if (!xmlDoc || !xmlDoc.getElementsByTagName('BLOCK')) {
console.log("nothings here");
return null;
}
//Add all xml blocks to blockArr
var blockArr = xmlDoc.getElementsByTagName('BLOCK');
var commentArr = xmlDoc.getElementsByTagName('COMMENT');
return blockArr[index].childNodes; ex return:[field, value, value, value, statement, next]
return blockArr[index].getAttribute('id'); ex return: 17
//The string comparison needs to be in all caps to check properly
if(blockArr[index].childNodes[index2].nodeName == 'STATEMENT')
Input Type = 1 Connecting a block to the right of the current block
Output Type = 2 Connecting a block to the left of the current block
Next Type = 3 Connecting a block to the one below it below the current block
Previous Type = 4 Connecting to a block above the current block
selectedNode = highlighted menu block
Type 1 = selectedNode.outputConnection
Type 2 = selectedNode.inputList[0].connection
Type 3 = var newBlock = Blockly.Accessibility.menu_nav.flyoutToWorkspace();
this.safeConnect(newBlock.previousConnection);
Type 4 = var newBlock = Blockly.Accessibility.menu_nav.flyoutToWorkspace();
this.safeConnect(newBlock.nextConnection);
if(toolboxChoices[i].outputConnection.check_[0] == this.storedConnection.check_[0])
ex. Boolean == Boolean
Blockly / Accessibility / in_block.js has functions to show the editor of various text fields. This code can be modified to get and set the values using:
this.selectionList[this.connectionsIndex]. -> showEditor_(); setValue(value); getValue();
- Some fields may have different syntax for these methods so it may be helpful to check the .js file of the relevant field first.
- Get and Set methods for accessing dropdown menus have already been created.