google / blockly-android

Blockly for Android
Apache License 2.0
672 stars 209 forks source link

Procedures / Functions Not Generating Code #740

Closed TheBrokenRail closed 5 years ago

TheBrokenRail commented 5 years ago

Current State

I added the procedure cateory to the toolbox and it seems to be mostly working, minus the code generation.

Code Generation

On the Blockly demo Simple Activity when trying to generate code with procedures in it it throws the error in logcat:

07-30 15:29:29.841 32379-32379/com.google.blockly.demo I/chromium: [INFO:CONSOLE(76)] "Error: Error: Extension "procedures_defnoreturn_mutator" not found.
        at Object.Blockly.Extensions.apply (file:///android_asset/blockly_compressed.js:1377:104)
        at Blockly.Block.jsonInit (file:///android_asset/blockly_compressed.js:1440:81)
        at Blockly.Block.init (file:///android_asset/background_compiler.html:34:22)
        at new Blockly.Block (file:///android_asset/blockly_compressed.js:1410:506)
        at Blockly.Workspace.newBlock (file:///android_asset/blockly_compressed.js:982:424)
        at Object.Blockly.Xml.domToBlockHeadless_ (file:///android_asset/blockly_compressed.js:1283:172)
        at Object.Blockly.Xml.domToBlock (file:///android_asset/blockly_compressed.js:1280:237)
        at Object.Blockly.Xml.domToWorkspace (file:///android_asset/blockly_compressed.js:1276:13)
        at generate (file:///android_asset/background_compiler.html:72:21)
        at <anonymous>:1:1", source: file:///android_asset/background_compiler.html (76)
AnmAtAnm commented 5 years ago

At this point, functions are not supported on either the master or develop branch of Blockly-Android.

If you're attempting to use functions, I strongly suggest using the functions branch, or my functions-remove branch. Both have significant problems when is comes to maintaining valid state through variables/procedure renames and removals. However, they are improvements upon the state of found in the develop branch.

That said, I just rebased the functions branch off the latest develop, and see the same problem. It looks like it is a relatively easy fix that requires pulling in some addition JavaScript from the web code. I believe that code is all found in blocks/procedures.js.

Mutators and extensions, are the pieces of block definitions that require each platform to reimplement, and since we are leaning on the web/JavaScript implementation for code generation, we need to have those extensions. I don't think the Android code has a clean way of pairing that extra JavaScript code with each block definition.

Since you are going beyond the currently implemented features of the Android implementation, I strongly recommend investigating using the web implementation in a Android WebView. Expect some demo code to pop up shortly.