a "run code" block!

Request a new command, feature, or improvement

Moderator: MSandro

Post Reply
MSandro
Posts: 162
Joined: Jul 26th, '17, 21:12

a "run code" block!

Post by MSandro » Jul 26th, '17, 21:36

Hi, it would be nice if you can add a block to GP wich can execute any code. It can be helpful maybe to read a text file and run this as a script with this block. And maybe the block should have a dropdown to choice between the GP-Syntax or other languages like VBScript, Batch, or C#...

Thank you very much.

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: a "run code" block!

Post by SimpleSi » Jul 28th, '17, 10:13

My take on this request would be (if doing it at all) that it should just allow a call to an underlying OS/shell command line and then let programmer deal with stuff afterwards

I do this in my ScratchGPIO that runs on a RaspberryPi - users can

broadcast "run xxxxxxxxxxxxxx" and it just does a call to the shell and executes xxxxxxxxxxxxx
0.png
0.png (2.33 KiB) Viewed 9442 times

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: a "run code" block!

Post by JohnM » Jul 29th, '17, 16:25

GP itself can only run GP code, just like the Java virtual machine can only run Java code, the Python interpreter can only run Python code, and the C++ compiler can only compile C++ code. That said, as SimpleSi points out, on platforms that support an OS shell (Mac/Linux/Windows but probably not Android, ChromeOS, or iOS) it would be possible to create a block that runs programs written in other languages via the OS shell. That might be a useful feature to add to GP at some point. (It's also potentially dangerous, so perhaps GP should ask the user's permission before running that command...)

It *is* possible to load and run GP code using the developer mode menu command "load source file...". For example, you can create a file named "tmp.gp" containing the line:

Code: Select all

showText 'Hello, GP!'
then enter developer mode and select "load source file..." from the right-click menu on the stage. A Workspace (text) window will pop up the given text in it.

What applications were you thinking of that would need this feature?

-- John

Post Reply