I want to write some custom blocks, so downloaded the source for the EspruinoWebIDE and did the following:
- Created a new file “EspruinoWebIDE\blockly\blockly_myfile.js”
- Included this file in a SCRIPT tag in the top of “EspruinoWebIDE\blockly\blockly.html”
- Proceeded to create my blocks – initially as defined using the Google BlockFactory and then added to blockly.html to present them in the UI
There are already a few files defining extra blocks – blockly_espruino.js is the main one and blockly_robots.js is a simpler one, that actually makes quite a good example to follow if you are doing your own.
Except when it isn’t. There were no obvious errors, and the ‘Send to Espruino’ always said ‘Sent’ but there was no outward sign that anything had happened.
Except in my case, no matter how it was written, generated, typed or checked, it was ignoring my code and I just could not spot what the error was. Eventually, I changed the order of the SCRIPT statements in blockly.html, wondering if there was some kind of load-order issue and it suddenly started working. Once I changed the order back again, it kept on working – so unfortunately I have no idea what was causing the problem, but just guessing some weird local caching issue or something not picking up my changes.
The only reason I’ve written this is that Googling for various hints as to what might cause the issue was failing me – even once I knew what the error was. So thought I’d write it down myself in case others have a similar issue – this might give someone else a clue.
Despite this rather irritating issue, I actually quite like Blockly.
In a future post, I’ll talk a bit more about what I’m actually doing with all this.