[Solved] How to make ren'py wait / pause for user input: click on npc, object, arrow for movement, in scene.

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
henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

[Solved] How to make ren'py wait / pause for user input: click on npc, object, arrow for movement, in scene.

#1 Post by henvu50 »

(i posted this in the cookbook, this post can be removed if need be)
This code allows you to wait until the user clicks an NPC, then you talk to the NPC, then once finished, it returns you to where you were before. You could click on the NPC over and over again if you want. IMPORTANT: With this code, you can create a scene with arrow navigation/movement as imagebuttons, multiple npc's who wait to be spoken to (represented as imagebuttons), or objects(bucket, hammer) laying about that you can interact with, represented as imagebuttons. The important part is that it always returns to the original waiting for input mode, which Ren'py achieves through the use of call screen.

CLICK FOR ANIMATED GIF PREVIEW - wait 2 seconds for it to kickin. This forum cannot show an animated gif, or maybe it can?
fefe11.gif

Code: Select all

image bg forestbackground = "areas/forest.jpg"

label start:
    #show your background
    scene bg forestbackground 
    jump loopTest
    return

label loopTest:

    #this screen contains imagebuttons of npcs, objects, navigation arrows, whatever you want.
    call screen wait_for_user_input

# this screen houses your imagebuttons of npcs, interactable objects like a hammer, bucket, or arrows that allow you to move from room to room
# see where it says ACTION JUMP??  You can perform any action there, like calling a function that moves you to a different location
# or jumps to a conversation with an npc, or jumps to a function after clicking a hammer, etc.
screen wait_for_user_input():
    modal True
    zorder 0
    hbox:
        xalign 0.5
        yalign 0.5
        imagebutton:

            # this string represents npc_idle.png and npc_hover.png in the image folder
            auto "npc_%s.png"

            focus_mask True
            action Jump ("talk_to_NPC_Bob")
            
label talk_to_NPC_Bob:

    "hello, i'm bob npc, let us speak."
    "I'm the player, bla bla bla"
    "we're finished."
    #IMPORTANT - this is the most important part, it returns back to the loop.
    # basically what happened is that you saw the npc, clicked on him, he disappears, from the background and can come to the foreground to talk with player
    # then after he's done talking, he returns back to the background.
    jump loopTest

Last edited by henvu50 on Sat Jun 12, 2021 1:53 am, edited 9 times in total.

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: How to make ren'py wait / pause for user input: click on npc, object, arrow for movement, in scene? (ongoing)

#2 Post by zmook »

When you have a screen button with a Return() action, that says "this screen is done and should go away".

The control flow you're talking about is complicated and I'm not sure offhand how to make it work, though I'm sure it's doable. I'd experiment with some combination of:
* `show` instead of `call` on screenThatHousesNPCimagebuttonAndHammerImagebutton, so it isn't primed to go away when the statement ends
* `pause` or a second blocking screen to keep the main script from advancing until you're ready for it
* `Jump()` or `SetVariable()` actions in screenThatHousesNPCimagebuttonAndHammerImagebutton, instead of Return()
* something that explicitly hides screenThatHousesNPCimagebuttonAndHammerImagebutton when you're done with it
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How to make ren'py wait / pause for user input: click on npc, object, arrow for movement, in scene? (ongoing)

#3 Post by Alex »

henvu50 wrote: Fri Jun 11, 2021 5:25 am ...

Code: Select all


    call screen screenThatHousesNPCimagebuttonAndHammerImagebutton

    # contains the return value of what the user clicked, the imagebutton is what holds the return value, see the screen action menu below
    $ act = _return 
Try it like

Code: Select all


    show screen screenThatHousesNPCimagebuttonAndHammerImagebutton

    # contains the return value of what the user clicked, the imagebutton is what holds the return value, see the screen action menu below
    $ act = ui.interact() 
https://www.renpy.org/doc/html/screen_p ... i.interact

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: How to make ren'py wait / pause for user input: click on npc, object, arrow for movement, in scene? (ongoing)

#4 Post by zmook »

Ah, so *that's* what ui.interact() is for!
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: [Solved] How to make ren'py wait / pause for user input: click on npc, object, arrow for movement, in scene.

#5 Post by henvu50 »

I didn't need to use ui.interact. Call screen worked just fine.

From what I read in the documentation. Call screen actually invokes ui.interact.

Perhaps ui.interact could make it better somehow? I modified and updated the original code. It works now perfectly.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]