1

I'm discovering Blockly as a useful tool to allow advanced users to "code without coding" some business logic rules, while also sandboxing their access. A classic visual rules engine.

I've seen that Blockly obviously supports variables which I assume are stored in some collection inside Blockly i.e. it doesn't go creating global JS vars?

In my regular JS code outside of Blockly, how can I set (or create) a Blockly variable and how can I read it? I am envisaging a situation where our code has an "update rules engine" block which will inject key values into Blockly variables so that Blockly data and our internal state are kept separate.

It seems obvious but my initial searches into how to interact with Blockly from code are not being fruitful.

Sébastien
  • 11,860
  • 11
  • 58
  • 78
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • You mention sandboxing. Are you using the [JS Interpreter](https://neil.fraser.name/software/JS-Interpreter/docs.html) during your execution? If so, consider `interpreter.setProperty(scope, 'varName', value);`. – Anm Jan 22 '18 at 21:11

1 Answers1

1

Just declare the vars in your JS file should do the trick. After your eval you can than use these variables, but watch out with eval, forsee enough security checks before executing your code...

Kind regards.