Sorry in advance for my English, I am french and just doing what I can to be readable. Also, I should tell you that I am blind, so I can't read any screenshots or pictures, only text (including code).
What I am trying to do is make a new engine to create audio games for blind people. I am using websocket-client in Python (with the run_forever method) to connect to a server which I have written in PHP.
Each time I try to start the socket my program gives an error: pale blue dot doesn't answer. It seems to cause a problem with my PC too, because my screen reader bugs out and freezes for some time.
I think the issue is with the websocket client because when I comment that out my code runs fine. The stranger thing is, when I watch the server logs, I can see the socket connection correctly established, but my program hangs until I go to the command line of my game and end the task with ctrl+c. When I do that, the websocket closes, and my game continues normally (except then I can no longer do anything that needs the websocket... sadly).
My code is split into multiples files. I have included the network and main files below. Hopefully somebody can help me find a solution to this problem. I usually work with PHP and am very new to Python.
Network Code
#global query_sended
#query_sended=lucia.audio_backend.Sound()
#query_sended.load("src/network/sended.ogg")
#global query_receved
#query_receved=lucia.audio_backend.Sound()
#query_receved.load("src/network/receved.ogg")
def on_error(ws,error):
print(error)
def on_close(ws):
print("closed")
def query_send(ws,query,notifiable):
print(query)
socket=ws.send(query)
if(notifiable==True):
#ddd
#query_sended.play()
#ddd
#all that is just put hir but not debuged so
#don't think you should take seriously a look on this method... :d :d
def on_message(socket,message):
#ddd
from inspect import getmembers
from pprint import pprint
pprint(getmembers(message))
#ddd
#query_receved.play()
interpretor=message.split("&&")
module=interpretor[0]
method=interpretor[1]
param=""
for i in range(2,len(interpretor)):
if(param==""):
param="\""+interpretor[i]+"\""
else:
param=param+",\""+interpretor[i]+"\""
print(module+"::"+method+"("+param+")")
global socket
def sockopen():
socket=websocket.WebSocketApp(
"ws://"+host+port,
on_message=on_message,
on_error=on_error,
on_close=on_close)
socket.run_forever()
Main Game Engine
from src import *
#variable used to know where we are in all of possibility in the script time line
wearein=""
#seting the logo of the game
logo=lucia.audio_backend.Sound()
logo.load("src/logo.ogg")
#showing the window of the game and give it a title
client=lucia.show_window("the pale blue dot")
#tel that: the client is in logo mod, and start playing
wearein="logo"
logo.play()
selectmod=True
#ini loop keeping the programe runing
#eccept if the player hit escape
while selectmod==True:
#even listener of lucia
lucia.process_events()
#small code use to kill the game if the player want to exit
if lucia.key_pressed(pygame.K_ESCAPE):
logo.stop()
logoff()
#if the logo is playing
if(wearein=="logo"):
if lucia.key_pressed(pygame.K_RETURN):
logo.stop()
modmenu=menu.mod.modmenu()
if(modmenu=="line"):
wearein="mainmenu"
selectmod=False
if(selectmod=="quite"):
logoff()
def onlinegame(wearein):
if lucia.key_pressed(pygame.K_ESCAPE):
logoff()
ws=network.sockopen()
#even listener of lucia
time.sleep(10)
lucia.process_events()
#if the player is in main menu
if(wearein=="mainmenu"):
client=lucia.show_window("The Pale Blue Dot, menu principal")
mainmenu=main.mainmenu()
#test on what value has been returned by the click on a buton of the menu
if(mainmenu=="register"):
print("register\n")
network.query_send(ws,"account&&initplayer&&ID",False)
wearein="register"
if(mainmenu=="login"):
print("connection")
wearein="login"
if(mainmenu=="quite"):
logoff()
#if the player come on register
if(wearein=="register"):
client=lucia.show_window("the pale blue dot, création d'un compte")
onlinegame(wearein)