Generated blocks wont recognise Blockly.Javascript

424 views
Skip to first unread message

Louis Capitanchik

unread,
Jul 31, 2012, 5:31:01 AM7/31/12
to blo...@googlegroups.com
Hello there, over the past few days I've been writing some Blockly documentation for people that I'm working with. In essence, the eventual goal is to use Blockly as a tool to teach young kids about parallel programming in a language neutral way, and then let more advanced users see the source code in a variety of languages such as C++ or Java by pulling the different conversions from a database. One step to doing this was creating a series of blocks that give the users the ability to run server side scripts - my test run of this uses the jquery $.post method.

In order to make the system a bit more scale-able and to allow new blocks to be added without having to modify the Blockly source every time, I've written a small program that takes a definition file for each php script and creates a block with the appropriate arguments (At the minute it only accepts INPUT_VALUE inputs, but this is just the first version). While it creates both the Blockly.Language segment and the Blockly.Javascript segment correctly, the block won't generate the Javascript upon running the code. Looking at the debugger, I'm getting a TypeError because the Blockly.Javascript object is undefined. This is the actual error:

Any help with the situation would be appreciated, as other blocks written into a static javascript file have worked fine (These use JCanvas to let users draw shapes) whereas the exact same code written into a static file throws the same error as the generated one. The PHP file itself isn't particularly elegant or well optimised at present, but it outputs code that looks like it should be correct.

This is where i'm hosting the tests: apps.engimatiworld.org.uk/VPE/
[It also has some other custom blocks, and some instructions explaining the basics as an example]

This line in the frame page;

<script type="text/javascript" src="blockly/language/en/server.php"></script>

loads this php file: http://pastebin.com/kpVu7nfK which, on the server, generates this Blockly code: http://pastebin.com/2CM662Pn

At present, the program has a single definition file (in plain text), here: apps.enigmaticworld.org.uk/VPE/scritps/examplePHPscript.def

It could just be something small or stupid that I've missed, or it could be a bug but it would be nice to finally fix the problem - if there is any other information that I can provide, I'd be glad to.



Louis Capitanchik

unread,
Jul 31, 2012, 5:53:02 AM7/31/12
to blo...@googlegroups.com
...And almost as soon as I posted this, I noticed that I had forgotten to capitalise the "s" in Javascript. After changing Blockly.Javascript to Blockly.JavaScript it works quite well, although there are still issues with actually getting a return value from the blocks. That ends several hours of hair-pulling frustration though, so I hope this can help other people that make similar mistakes with capitalisation.

Neil Fraser

unread,
Jul 31, 2012, 1:49:03 PM7/31/12
to blo...@googlegroups.com
On 31 July 2012 02:53, Louis Capitanchik <ljcap...@googlemail.com> wrote:
...And almost as soon as I posted this, I noticed that I had forgotten to capitalise the "s" in Javascript. After changing Blockly.Javascript to Blockly.JavaScript it works quite well, although there are still issues with actually getting a return value from the blocks. That ends several hours of hair-pulling frustration though, so I hope this can help other people that make similar mistakes with capitalisation. 

Glad you found the error.  This is why Blockly's own variables are case-insensitive.  I never understood why any language would consider case-sensitive variables to be a feature.

That said, it could be worse.  Micro-Soft BASIC had variables that were only significant for the first two letters.  So 'count1', 'count2' and 'colour' were all equivalent.  Fun times.

--
Neil Fraser
http://neil.fraser.name
Reply all
Reply to author
Forward
0 new messages