Discuss Scratch

Cekobelinski
Scratcher
3 posts

Scratch 2.0 with Python Communication

Hello everyone,

In my task, I need to communicate my Python code with Scratch Projects.
I researched the ways from Scratch wiki and succeed that with remote sensor connections in Scratch v1.4.
But I couldn't reach the same success with other alternatives (blocktext , pyscratch2 and ScratchAPI) for Scratch 2.0

Here are the links I've checked:
https://wiki.scratch.mit.edu/wiki/Python
https://wiki.scratch.mit.edu/wiki/Communicating_to_Scratch_via_Python

If you have any other ideas or ways to show how to create a communication between Python and Scratch applications, please contact with me.

Thanks for your support.
SolarWind12
Scratcher
500+ posts

Scratch 2.0 with Python Communication

Remote Sensor Connections should work with 2.0


Cekobelinski
Scratcher
3 posts

Scratch 2.0 with Python Communication

SolarWind12 wrote:

Remote Sensor Connections should work with 2.0

Hey, SolarWind12

Unfortunately, Scratch 2.0 doesn't support RSC.
Scratch wiki says : “Note that the extension mechanisms for Scratch 1.4 and Scratch 2.0 are quite different, and are not compatible.”

I'm still waiting for any other ideas and supports.
Thanks for your interest.
SimpleScratch
Scratcher
100+ posts

Scratch 2.0 with Python Communication

Basic info is that you need to write javascript code that talks to your python program
Websockets is usually the easiest protocol to use do do this

Checkout ScratchX website
TheUltimatum
Scratcher
1000+ posts

Scratch 2.0 with Python Communication

The new cloud system runs on websockets. You'll need to write a script in python that successfully authenticates with the API and then sends data to and from the project via cloud variables.

Cekobelinski
Scratcher
3 posts

Scratch 2.0 with Python Communication

TheUltimatum wrote:

The new cloud system runs on websockets. You'll need to write a script in python that successfully authenticates with the API and then sends data to and from the project via cloud variables.

Hey, TheUltimatum

Because of creating a communication via cloud requires internet connection, my projects won't work properly If I run them on Offline Editor without internet. A solution that helps to transfer local variables of Scratch to Python as Offline would be perfect.

In the other hand, I have doubts about the communication speed by cloud connection.
TheUltimatum
Scratcher
1000+ posts

Scratch 2.0 with Python Communication

Cekobelinski wrote:

TheUltimatum wrote:

The new cloud system runs on websockets. You'll need to write a script in python that successfully authenticates with the API and then sends data to and from the project via cloud variables.

Hey, TheUltimatum

Because of creating a communication via cloud requires internet connection, my projects won't work properly If I run them on Offline Editor without internet. A solution that helps to transfer local variables of Scratch to Python as Offline would be perfect.

In the other hand, I have doubts about the communication speed by cloud connection.
Speed via cloud variables isn't amazingly fast but seems good enough for what you are trying to do. But since you say you want your projects to run offline the solution set is much smaller. One of the possible ways you could do this would be writing a program to press keys in python for example using pyautogui. And send these keys to a scratch program you can then proceed to buffer the keystrokes in the scratch program. After the buffering has finished you could broadcast the buffered keys or do whatever else you'd like with the input.

Jonathan50
Scratcher
1000+ posts

Scratch 2.0 with Python Communication

The Scratch 2.0 offline editor does extensions differently and it's possible to make HTTP extensions although I think it was deprecated so you're not really supposed to use it anymore.

ae2d2bcb-e9e3-4f9c-a847-290d71bd8bfd 222ec087-6694-42cf-8c41-064e9066f004

Powered by DjangoBB

Standard | Mobile