Hi,
I am using blockly to create a game for young kids, and as a challenge I want to have a counter for the number of blocks the user can put onto the screen.
I'm wondering how I can keep track of the blocks in the workspace once the user has dragged and dropped one onto it.
I started by looking at the Blockly.Generator.prototype.workspaceToCode() function and tried to get the number of blocks out of it as seen below:
Blockly.Generator.prototype.workspaceToCode = function(workspace) {
if (!workspace) {
// Backwards compatability from before there could be multiple workspaces.
console.warn('No workspace specified in workspaceToCode call. Guessing.');
workspace = Blockly.getMainWorkspace();
}
var code = [];
this.init(workspace);
var blocks = workspace.getTopBlocks(true);
//New code below
console.log(blocks);
//New code above
...
}
I thought the "blocks" variable might contain the current blocks in the workspace but it's always empty so I might be looking at the wrong spot.
Just wondering if anyone has any thoughts on this.
Thanks,
Prateek