Best way to wait for user input?

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
Message
Author
User avatar
docclox
Newbie
Posts: 20
Joined: Thu Oct 12, 2017 6:26 am
Contact:

Best way to wait for user input?

#1 Post by docclox »

One thing I've noticed is that, left to it self, Renpy runs off the end of the current scene and straight into the next one. Which is very useful if you're doing a pure VN of course, but if your project is driven by screen interaction, you need to suspend the narrative until the player clicks on something.

What's the recommended way to do this? The approach I've been using is:

Code: Select all

label input_loop:
    while True:
        pause
That jumps out of the pause if the user clicks a button with a jump action, the pause should keep it from running too hot, and the loop means that if the user clicks around randomly we stay in the loop. It's just seems a little ... inelegant, I suppose.

Is there a better idiom for this sort of thing? Purely out of curiosity.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Best way to wait for user input?

#2 Post by Imperf3kt »

Renpy will not continue until you click, thats how it works.
If your game is continuing automatically, are you sure AFM is not enabled? (auto forward mode)
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
docclox
Newbie
Posts: 20
Joined: Thu Oct 12, 2017 6:26 am
Contact:

Re: Best way to wait for user input?

#3 Post by docclox »

Yes, I get it.

But if it gets to the end of a section of narrative, it runs off the end of that and onto the next one. If I jump it somewhere else, it continues down the file looking for narrative to display. I need a way to get it to stop talking and wait for a button press.

I was curious how others had handled it.

[edit]

Nevermind: the tutorials main menu does exactly what I wanted.

bob_54321
Newbie
Posts: 2
Joined: Sat Nov 04, 2017 4:06 pm
Contact:

Re: Best way to wait for user input?

#4 Post by bob_54321 »

docclox wrote: Tue Oct 24, 2017 4:45 am Nevermind: the tutorials main menu does exactly what I wanted.
Could you post here your solution? I would like to see your code.

User avatar
docclox
Newbie
Posts: 20
Joined: Thu Oct 12, 2017 6:26 am
Contact:

Re: Best way to wait for user input?

#5 Post by docclox »

Basically, I have a UI panel with buttons to move, talk, etc, and I put that up with call rather than show.

So this means that the UI gets displayed and execution waits until it gets a click. Then I return back with a label string. Then I do some bookkeeping, call the label and when that returns I loop back and call the UI again.

I'll post some code in a bit (not at my dev machine right now) but that's the essence of it.

User avatar
docclox
Newbie
Posts: 20
Joined: Thu Oct 12, 2017 6:26 am
Contact:

Re: Best way to wait for user input?

#6 Post by docclox »

Sorry to take so long - things have been a bit hectic. "ibox" is my interaction box - currently just three buttons for look, talk, map. I call the screen and it returns either "map" or else a label string based on chapter and location variables. So if the location (set by the map screen) was "bar" then it might return "explore_bar_talk"

Code: Select all

# The game starts here.
label start:
    call chargen
    call prologue
#
#   set some useful variables
#
    $ __first_loop = True
    $ game.chapter = "explore"
#
#   OK: explore activity loop
#
    while True:
        call screen ibox
#
#       if it's the map button, we need to show the map GUI and get a button click from that
#       let's wrap that in one call
#
        if _return.kind == "map":
            call do_map_screen
#
#       otherwise, the label string will match a label based on chapter and current location
#
        else:
            call expression _return.label_str pass(_return) from __stuffy_func
        # and then we go round again
        # I need to think about how to break out of this properly.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Ocelot