I am new on RenPy, I am testing some possibility on the engine.
I am trying to do below but no help in coding, and seeking for advice:
1. I am using a input to ask for data
2. Popup a loading screen after enter
3. Use urllib2 to send request to server and wait for response
4. Off the loading screen
5. Output the result in dialog
My screen coding as below:
Code: Select all
screen overlay_loading():
tag loading
zorder 80
modal True
vbox:
xalign 0.5
yalign 0.5
text "{color=ffffff}Loading...{/color}"
So I have tried use renpy.invoke_in_thread in step 3 to call a function, and close the screen (step 4) within it
But after that, I cannot go back to main thread to do step 5
Below is part of code for step 3 without calling any loading screen
Code: Select all
label inputsearch:
$ searchdata = renpy.input("Input your search content!")
$ searchdata = searchdata.strip()
jump check_inputsearch
label check_inputsearch:
if not searchdata:
"Search content cannot empty!"
jump inputsearch
else:
jump senddata
label senddata:
$ myresult = _("")
init python:
import urllib, urllib2, socket, json
def function_loading(isopen):
if isopen:
renpy.call_screen("overlay_loading")
else:
renpy.hide_screen("loading")
def function_searchdata(inputdata):
try:
print(inputdata)
data = urllib.urlencode({ "r" : inputdata }).encode("utf-8")
req = urllib2.Request("http://apicall/")
req.add_header('Content-Type','application/x-www-form-urlencoded; charset=utf-8')
responsedata = urllib2.urlopen(req,data,30)
result = json.loads(responsedata.read())
global myresult
myresult = result['d']
#function_loading(False)
print("off")
print(myresult)
except urllib2.URLError as e:
print type(e) #not catch
except socket.timeout as e:
print type(e) #catched
#raise MyException("There was an error: %r" % e)
python:
#renpy.call_screen("overlay_loading")
function_searchdata(searchdata)
#renpy.invoke_in_thread(function_searchdata, searchdata)
#function_loading(True)
e "Return result: [myresult]"
# This ends the game.
return
Thanks for reading.