To Stop execution of blockly code

789 views
Skip to first unread message

prashant...@gmail.com

unread,
Dec 13, 2018, 2:19:34 AM12/13/18
to Blockly
Hi 

i am using eval to execute custom blocks and wanted to know that how can i stop execution of blockly code on a button click.
please provide me some reference or solution regarding my query.

thanks,
prashant

Beka Westberg

unread,
Dec 13, 2018, 10:14:14 AM12/13/18
to Blockly
Hi prashant,

As far as I know there's no simple way to do this with eval, but luckily there is still a solution! You're going to want to take a look at the JS Interpreter.

So what you're going to do will depend a bit on whether you want to /stop/ execution or /pause/ execution.

1. Run the code on a timeout, either like this where it runs each "step" on a timeout, or like this where it waits until it hits an async call within the code (demo), and then waits for a timeout.
2a. If you want to simply /stop/ the code execution (so if someone were to hit play again it would start from the beginning) I believe all you need to do is reset the interpreter and it should stop.
2b. If you want to /pause/ the code execution (if someone were to hit play again it would start from where it was paused) you'll need to reset & serialize/deserialize the interpreter (demo, docs).

This is a good reference for doing the asyncronous execution (demo).

It can be tricky, but the interpreter is really cool once you get it set up!
Beka
Reply all
Reply to author
Forward
0 new messages