i get this error in the 32 line in every time i run the game as a client
my client code
#------------Setup--------------#
from GameLogic import *
import GameLogic as GameLogic
import bge
from socket import *
import socket
import pickle
cont = GameLogic.getCurrentController()
owner = cont.owner
#obj = cont.owner
if not owner['OneTime']:
ServerIP = GameLogic.IP
Serverport = 677
Clientname = ''
ClientPort = 678
GameLogic.sClient = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
GameLogic.sClient.bind((Clientname,ClientPort))
GameLogic.host = (ServerIP,Serverport)
GameLogic.sClient.setblocking(0)
owner['OneTime'] = 1
PosYou = owner.worldPosition
scene = getCurrentScene()
Server = scene.objects["Server"]
PosServer = [0,0,0]
#------------RECEIVE/SEND--------------#
Data = pickle.dumps((PosYou))
GameLogic.sClient.sendto(Data,GameLogic.host)
try:
Data, SRIP = GameLogic.sClient.recvfrom(1024)
UPData = loads(Data)
PosServer = [UPData[0],UPData[1],UPData[2]]
Server.setPosition(PosServer)
except:
pass
#---------------THE-END----------------#
Monster
(Monster)
April 19, 2016, 1:50am
2
so that’s mean i should write the line like that ?
Data = pickle.dump(PosYou)
agoose77
(agoose77)
April 19, 2016, 3:49am
4
No - Monster was right, there is a pickle.dump function, which writes to a file, but as he wrote, you must provide an open file.
There is also a dumps method, which instead of writing to a file, returns a bytes string. It seems to me that the error you’ve received suggests you didn’t write “pickle.dumps”, but wrote instead “dumps”. Check you’re looking at the right textblock, and that you’ve copied correctly here.
that’s are my file you can check that by your self :3
Attachments
WSAG-BasicNetwork.blend (354 KB)
agoose77
(agoose77)
April 19, 2016, 3:55pm
6
In the client module, you’ve not imported dumps (or loads).
Either add “from pickle import dumps, loads”, replace “dumps” with “pickle.dumps” and “loads” with “pickle.loads”, or add “from pickle import *”
agoose77:
In the client module, you’ve not imported dumps (or loads).
Either add “from pickle import dumps, loads”, replace “dumps” with “pickle.dumps” and “loads” with “pickle.loads”, or add “from pickle import *”
i get this error after the edit :3
Traceback (most recent call last):
File “Client.py”, line 33, in <module>
_pickle.PicklingError: Can’t pickle <class ‘Vector’>: attribute lookup Vector on builtins failed
Monster
(Monster)
April 19, 2016, 10:55pm
8
Convert the mathutils.Vector to a list (and back after unpickle).
so that what you mean changing PosYou = owner.worldPosition to PosYou = list(owner.worldPosition) and set PosServer = [UPData[0],UPData[1],UPData[2]] and adding this line owner.worldPosition = PosServer ?
agoose77
(agoose77)
April 20, 2016, 5:15am
10
Nearly. You can quickly convert a vector into a tuple (which is also serialisable, like lists are) using
some_tuple = some_vector[:]
You can convert this back into vector form if you want to do some vector maths on it using
from mathutils import Vector
my_vector = Vector(my_tuple)
Or, if you’re just assigning it to the game object’s position, you can set it directly.
my_obj.worldPosition = my_tuple
that’s are my last edit and i did’t get any error in the consle but the game did’t run as multiplayer :3 i don’t know what i should do :3
Attachments
WSAG-BasicNetwork.blend (355 KB)
agoose77
(agoose77)
April 20, 2016, 6:32am
12
There’s a try except block in both the server and client scripts. Change
except:
pass
with
except OSError:
pass
This way, any non socket OSErrors will be printed (technically should check the error code as well).
You’ll see that the server has an error at the top -
if owner['OneTime']
should be
if not owner['OneTime']
The IP is not valid either. Use localhost for local-multiplayer, or ‘’ to bind externally.
i added the lines as you write
and that’s OSError not OsError
but that’s still did’t work are thay working with you ?
agoose77
(agoose77)
April 20, 2016, 11:10am
14
So you fixed the IP and the server code to use a not?
Have you pressed F1 and F2 to start the client and server?
yes i fixed the ip to “localhost” and used if not and pressed f1 and f2
no one know the soultion ?
agoose77
(agoose77)
April 22, 2016, 4:54am
17
You also need to make sure the server and client are pickling lists (or tuples) not Vectors, and that the correct IP address is used in setup and server.py
use “localhost” for local testing
that’s what you mean about pickling lists ?
PosYou = list(owner.worldPosition)
Data = pickle.dumps((PosYou))
agoose77
(agoose77)
April 22, 2016, 6:21am
19
yes, or use as_tuple = vec[:]
i did that but still did’t worked and i used “localhost” as ip :3 so what’s the proplem there are’t any errors in terminal