Create a loading screen when sending server request

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Posts: 1
Joined: Wed Sep 25, 2019 8:29 am

Create a loading screen when sending server request

#1 Post by bp7 » Wed Sep 25, 2019 8:47 am

Hi All

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

        xalign 0.5
        yalign 0.5

        text "{color=ffffff}Loading...{/color}"
When i am working on 2, if the screen is opened, step 3 will not run and hold

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
        jump senddata
label senddata:
    $ myresult = _("")

    init python:
        import urllib, urllib2, socket, json
        def function_loading(isopen):
            if isopen:

        def function_searchdata(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(

                global myresult 
                myresult = result['d']
            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)


        #renpy.invoke_in_thread(function_searchdata, searchdata)

    e "Return result: [myresult]"

    # This ends the game.

I am using RenPy

Thanks for reading.

User avatar
Eileen-Class Veteran
Posts: 1458
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain

Re: Create a loading screen when sending server request

#2 Post by xavimat » Thu Sep 26, 2019 1:25 pm

I haven't checked all your code, but you probably need renpy.show_screen() instead of renpy.call_screen().

Also, don't put "init python" inside a label. Renpy will execute all "init whatever" at init time, so it's wasting indentation and your code is more confusing.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Post Reply

Who is online

Users browsing this forum: oatnoodles