This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-12-18 17:26:04

flashgocrazy
Scratcher
Registered: 2011-01-12
Posts: 500+

Python mesh client help?

I made a client for my wwm called worldzord,
I need help for it here is its code

Code:

#Worldzord client V1.0

from array import array
import socket
import time

HOST = '127.0.0.1'
PORT = 42001
def sendScratchCommand(cmd):
    n = len(cmd)
    a = array('c')
    a.append(chr((n >> 24) & 0xFF))
    a.append(chr((n >> 16) & 0xFF))
    a.append(chr((n >>  8) & 0xFF))
    a.append(chr(n & 0xFF))
    scratchSock.send(a.tostring() + cmd)

print("connecting...")
scratchSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
scratchSock.connect((HOST, PORT))
print("connected")
print ("Please type in your scratch syntax for help, see the source code")
myName = input()
sendScratchCommand(myName)
print("the command: " + myName + " was sent to scratch sucessfully!")
time.sleep(0.5)
 #help:
       #remote sensor syntax: sensor-update "var name" value
       #brodcast syntax: brodcast "name here"

For some reason I keep getting this error

Traceback (most recent call last):
  File "C:\Users\Zeus\Desktop\python client.pyw", line 24, in <module>
    sendScratchCommand(myName)
  File "C:\Users\Zeus\Desktop\python client.pyw", line 11, in sendScratchCommand
    a = array('c')
ValueError: bad typecode (must be b, B, u, h, H, i, I, l, L, f or d)

can somebody fix this code and also make it so it repeats forever?

Last edited by flashgocrazy (2011-12-18 17:26:58)


◕‿◕

Offline

 

#2 2011-12-18 18:09:35

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Python mesh client help?

flashgocrazy wrote:

I made a client for my wwm called worldzord,
I need help for it here is its code

Code:

#Worldzord client V1.0

from array import array
import socket
import time

HOST = '127.0.0.1'
PORT = 42001
def sendScratchCommand(cmd):
    n = len(cmd)
    a = array('c')
    a.append(chr((n >> 24) & 0xFF))
    a.append(chr((n >> 16) & 0xFF))
    a.append(chr((n >>  8) & 0xFF))
    a.append(chr(n & 0xFF))
    scratchSock.send(a.tostring() + cmd)

print("connecting...")
scratchSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
scratchSock.connect((HOST, PORT))
print("connected")
print ("Please type in your scratch syntax for help, see the source code")
myName = input()
sendScratchCommand(myName)
print("the command: " + myName + " was sent to scratch sucessfully!")
time.sleep(0.5)
 #help:
       #remote sensor syntax: sensor-update "var name" value
       #brodcast syntax: brodcast "name here"

For some reason I keep getting this error

Traceback (most recent call last):
  File "C:\Users\Zeus\Desktop\python client.pyw", line 24, in <module>
    sendScratchCommand(myName)
  File "C:\Users\Zeus\Desktop\python client.pyw", line 11, in sendScratchCommand
    a = array('c')
ValueError: bad typecode (must be b, B, u, h, H, i, I, l, L, f or d)

can somebody fix this code and also make it so it repeats forever?

You have python 3 don't you?
Downgrade to 2.7


Fork Clamor on GitHub!

Offline

 

#3 2011-12-18 21:25:47

nickbrickmaster
Scratcher
Registered: 2010-02-02
Posts: 500+

Re: Python mesh client help?

It seems you have a wrong type of typecode. Try one of them that the error suggested.


Ask me what I'm doing, wait an hour than roll a die, if it's 4-6, I'm playing Skyrim, if it's 1, I'm eating, if it's 2-3 I'm programming.
Steam: nickbrickmaster | RotMG: PwnThemAll | Minecraft: nickbrickmaster | League Of Legends: BaneOfTitans

Offline

 

#4 2011-12-18 23:43:43

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Python mesh client help?

nickbrickmaster wrote:

It seems you have a wrong type of typecode. Try one of them that the error suggested.

I got the same thing when I had Python 3.3

I downgraded and it all went away  wink


Fork Clamor on GitHub!

Offline

 

#5 2011-12-18 23:48:25

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: Python mesh client help?

And looping forever might not be the best choice, as it would be hard to stop and take up lots of RAM.


Hai.

Offline

 

#6 2011-12-19 11:00:56

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Python mesh client help?

I haven't used Python 3, but instead of a = array('c') try a = ['c']. It may/should work.

Offline

 

#7 2011-12-19 12:05:23

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Python mesh client help?

Magnie wrote:

I haven't used Python 3, but instead of a = array('c') try a = ['c']. It may/should work.

I think I tried that when I had Python 3, but it didn't work...I think all that does is create an array with one index: 'c'

But it's worth a try


Fork Clamor on GitHub!

Offline

 

#8 2011-12-19 15:12:26

TRocket
Scratcher
Registered: 2009-08-18
Posts: 1000+

Re: Python mesh client help?

is this mesh or remote sensor connections?


http://i.imgur.com/1QqnHxQ.png

Offline

 

#9 2011-12-19 15:56:57

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Python mesh client help?

TRocket wrote:

is this mesh or remote sensor connections?

Mesh with Remote Sensors I think.

Offline

 

Board footer