How to use the Screen Input not during the game?

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
missiya4
Newbie
Posts: 17
Joined: Fri Oct 22, 2021 11:18 am
Contact:

How to use the Screen Input not during the game?

#1 Post by missiya4 »

Hi all. I want to create my own small console from the settings menu.
I created an "Open Console" button in the game settings, which opens the corresponding screen with Input and immediately provides the ability to enter text. The problem is that I don't know how to properly hook the result after pressing the Enter button. Also, after pressing the Enter button, the game automatically starts (the next iteration happens, as I understand it). How do I avoid this and just get the input string in the python code?
Interested only for mobile devices.

Current Code:

Code: Select all

screen dev_console_settings_btn():
    if renpy.variant("touch"):
        textbutton _("{size=42}Open Console{/size}") action Function(OpenConsole):
            align(.95, .04)

screen dev_console():
    zorder 9992
    
    frame:
        align(.5,1.0) xysize(1600, 770)

        vbox:
            input copypaste True

init python:
    DEV_bConsole = False
    def OpenConsole():
        global DEV_bConsole
        DEV_bConsole = not DEV_bConsole
        if DEV_bConsole == True:
            renpy.show_screen(_screen_name="dev_console")
        else:
            renpy.hide_screen("dev_console")


User avatar
Milkymalk
Miko-Class Veteran
Posts: 762
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: How to use the Screen Input not during the game?

#2 Post by Milkymalk »

Look at the description for input:
https://renpy.org/doc/html/screens.html ... nput#input

You are only showing the console screen, but you need to call it. You can scrap the function for toggling the screen completely, a called screen will hide when it returns something, which input does.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

missiya4
Newbie
Posts: 17
Joined: Fri Oct 22, 2021 11:18 am
Contact:

Re: How to use the Screen Input not during the game?

#3 Post by missiya4 »

Milkymalk wrote: Sun Apr 03, 2022 2:48 pm You are only showing the console screen, but you need to call it.
Yep, you're right. Thank you, but I've already solved it through "renpy.show_screen" and executing the label with "renpy.call_in_new_context" for this.
I don't think my version is the short and proper solution either :? , but it works great.

Code: Select all

# (Can be showed by any other button's action.)
screen dev_console_settings_btn():
    textbutton _("{size=42}Open Console{/size}") action Function(renpy.show_screen, _screen_name="dev_console")

screen dev_console():
    zorder 9992
    
    frame:
        textbutton _("Enter the command") action Function(renpy.call_in_new_context, label="dev_console_input_command_label")
        textbutton _("Close console") action Function(renpy.hide_screen, tag="dev_console")

init python:
    DEV_consoleTypingBlocked = False

label dev_console_input_command_label():
    python:
        if not DEV_consoleTypingBlocked:
            DEV_consoleTypingBlocked = True   # Prevent calling twice.
            renpy.show_screen(_screen_name="dev_console")   # (Otherwise the console is hidden)
            # Wait typing...
            curr_command = renpy.input(_("Enter a command..."), screen="console_input")
            ExecuteConsoleCommand(command=curr_command)   # Execute necessary command. 
            DEV_consoleTypingBlocked = False
            renpy.restart_interaction() # refresh screen.
            del curr_command    # clean memory

screen console_input(prompt):  # A custom "input" screen is used because I can't see the input field when called from the main menu.
    zorder 9994

    frame:
        align (.5,.0) yoffset 100 xfill True ysize 160
        vbox:
            align (.5,.0)

            null height 10
            text prompt:
                align (.5,.0) size 40
            null height 20
            input:
                id "input"
                align (.5,.0) size 50

Post Reply

Who is online

Users browsing this forum: No registered users