Creating a Block in Blockly #260
Replies: 13 comments
-
Posted at 2014-04-08 by @gfwilliams Hi Rehman, Great! To see the block, you need to add it to the toolbox, which is in |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-16 by rsm Thanks Gordon, that worked :) I have two more questions though:
Thanks, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-16 by @gfwilliams Great! To see the code, you might just be able to open the 'inspect element' window and go to the console - when you send to Espruino it should dump the code out there... You could always click in the left-hand pane and use up-arrow to check the history to see what was sent to Espruino... Your issue with the timeouts is that they're both run at basically the same time. If you do a timeout of 4000 for the first, and then 8000 for the second, it should work as you expect? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-16 by rsm Thanks Gordon. The up-arrow trick works well to see the code sent by Blockly. I'm not sure how to open the 'inspect element' window. You're also right about the two calls happening at the same time. I read up on setTimeout() and see that it actually forks a new process that is executed at the specified time. But it is non-blocking. Is there a way to block? I tried writing a sleep() function, but that's not working either (see below). I also read that there's a way to get setTimeout() to work the way I want, but I can't get it to work. Thanks,
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-16 by @gfwilliams Blocking is really bad idea in Espruino, so it's intentionally made really difficult! Espruino isn't pre-emptive so a long loop like that stop all other timers/watches from executing. Is there any reason you can't do the following:
That will execute the first timeout, and will then start the second one once the first has completed... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-16 by rsm Hmm, nested setTimeout() functions. That works too. But unfortunately it doesn't solve my problem :( Thanks again, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-17 by @gfwilliams Well, you can easily do that, but you have to stack blocks inside of each other:
I'm not sure that's actually such a hard thing to explain to children? It's harder for normal software developers because we're used to having things run linearly. Failing that, there might be a way to modify blockly - but that's a question to ask the developers of that... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-18 by rsm Thanks Gordon :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-20 by DrAzzy This works, not that I think doing this is a good idea in most circumstances.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-27 by rsm Thanks guys. I tried following your advice to not use blocking code, but ran into another problem. I can't change that value of variables inside the function prototype. For example, this code works:
But this code does not:
The result is that it moves to position 1.45 at time 1000. So I guess it has already run "pos -= posInc;" three times before it first calls the analogWrite() function. Please help, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-28 by DrAzzy You need to put the pos-=posInc; inside the timeout. Right now, that is being run between the setting of the timeouts. So all three timeouts get set, and pos gets incremented three times. Then, a second later, the timeouts start firing, with pos at it's final value for all of the timeouts, because it got incremented way back when the timeouts were set. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-28 by rsm Ah, that works well. Thanks DrAzzy. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-28 by @gfwilliams The code's right at the top of You could probably fix it by adding to the code in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-04-07 by rsm
Hi,
I'm just trying to create my first block in Blockly for Espurino.
I'm running the Chrome extension offline and editing the file "blockly_espruino.js".
I made one function of the form "Blockly.Language.espruino_newFunction = {}" and one of the form "Blockly.JavaScript.espruino_newFunction = function() {}".
But how do I actually see my new block? Is there a setting or something I'm missing? If anyone could list the steps to create a new block, I would really appreciate it.
Thanks,
Rehman
Beta Was this translation helpful? Give feedback.
All reactions