HI:
I am using Python to get data from Scratch
if scratch send a broadcast, after my python program receive data will do someting
My Scratch will send a broadcast: YesLesson
A part of my python source code below:
while True:
time.sleep(0.01)
data = scratchSock.recv(1024)
if data=="broadcast "+'"YesLesson"':
print(data)
-----------------------------------------------------------
this is not working
I have stucked here for a few days...
can somebody tell me how to solve this problem?
Thanks
Offline
Try this tutorial: http://wiki.scratch.mit.edu/wiki/Commun … with_a_GUI Hope it helps!
Offline
That is because you are only checking for "broadcast YesLesson", you need to look for the length at the beginning of the message, you also need to put double-quotes around your message:
\x0\x0\x0\x15broadcast "YesLesson"
Try this code:
while True:
time.sleep(0.01)
data = scratchSock.recv(1024)
if data == '\x00\x00\x00\x15broadcast "YesLesson"':
print(data)Have you set up your scratchSock connection as well? (Was the code you provided the full code, or not?)
Last edited by Magnie (2012-05-23 10:11:41)
Offline
Magnie wrote:
That is because you are only checking for "broadcast YesLesson", you need to look for the length at the beginning of the message, you also need to put double-quotes around your message:
Code:
\x0\x0\x0\x15broadcast "YesLesson"Try this code:
Code:
while True: time.sleep(0.01) data = scratchSock.recv(1024) if data == '\x00\x00\x00\x15broadcast "YesLesson"': print(data)Have you set up your scratchSock connection as well? (Was the code you provided the full code, or not?)
can you tell me what is this means: x00\x00\x00\x15
I am not pretty sure about that.
this is just a part of my source code,I want to make a python website to connect scratch
Offline
ARLUMI wrote:
can you tell me what is this means: x00\x00\x00\x15
I am not pretty sure about that.
this is just a part of my source code,I want to make a python website to connect scratch
The first 4 bytes, "\x00\x00\x00\x15", tell you the length of the message. "\x15" is hexadecimal for 21. You could parse them, but it's probably easier to ignore them:
data = data[4:]
Offline