Discuss Scratch

pancakeaccount
New to Scratch
4 posts

Python Help

Hi everyone, I'm new to the scratch website and have a question which I can't find an answer to. I'm working with a Raspberry Pi having Python and Scratch talk back and forth. Is it possible to create a variable in Python and have it show up in Scratch or can Python only receive variables from Scratch?
davidkt
Scratcher
1000+ posts

Python Help

You could create a variable in Scratch and edit it using Python…

Remember when I looked like this? I still do.


Float, my Scratch 2.0 mod | My (somewhat under-construction) blog
pancakeaccount
New to Scratch
4 posts

Python Help

So it isn't possible to initialize a variable in Python then have it be created in Scratch? Would and outside technology like Scratchpy help with this?
blob8108
Scratcher
1000+ posts

Python Help

pancakeaccount wrote:

Would and outside technology like Scratchpy help with this?
Sounds like it.

Check out Python#Scratch_1.4 on the wiki: there are a few libraries like scratch.py that help you send data in Python to/from Scratch. You can create a “sensor variable” in Python and read it in Scratch using the sensor value of block.

tosh · slowly becoming a grown-up adult and very confused about it
pancakeaccount
New to Scratch
4 posts

Python Help

Check out Python#Scratch_1.4 on the wiki: there are a few libraries like scratch.py that help you send data in Python to/from Scratch. You can create a “sensor variable” in Python and read it in Scratch using the sensor value of block.

That seems to work but is there any way to have that value be read into Scratch as an actual variable rather than a sensor? So that when a python program is run the variables are automatically created?

Last edited by pancakeaccount (June 20, 2014 15:45:11)

blob8108
Scratcher
1000+ posts

Python Help

pancakeaccount wrote:

is there any way to have that value be read into Scratch as an actual variable rather than a sensor?
No, you have to use the sensor value block.

tosh · slowly becoming a grown-up adult and very confused about it
Magnie
Scratcher
100+ posts

Python Help

blob8108 is correct. You can only use sensor-variables to read information from the Python program. If you really want to use an actual variable, you'll have to forward the value from the sensor to the variable. You also won't be able to dynamically find the name of the sensors either.

▴ ▾ ▴ Macbook Pro 13" 2015 i5-5257U 8GB RAM - MacOS Sierra - Vivaldi v1.7 ▴ ▾ ▴
There are 10 types of people in this world, those who understand binary, those who don't, and those who know ternary.

Powered by DjangoBB