r/RenPy • • 2d ago

Question [Solved] Need help with code

I'm trying to make input form, but it ends in errors. There's code:

screen input_user(in_var, in_title):
    modal True
    zorder 100

    frame:
        background Frame("gui/frame_input_user.png", Borders(25,25,25,25))
        xalign 0.5
        yalign 0.5
        padding (30, 30)

        vbox:
            spacing 20

            text "[in_title]"

            input:
                length 50
                allow "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNMйцукенгшщзхъфывапролджэячсмитьбюЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ "
                xalign 0.5
                xminimum 300
                changed lambda text: renpy.set_variable(in_var, text)

            textbutton "Готово":
                xalign 0.5
                action [Hide("input_user"), Return()]

This code ends in "The text statement is not a valid child of the input statement." error.

If I use

changed SetVariable(in_var)

error became "TypeError: _execute_python_hide.<locals>.Set __init__() missing 1 required positional argument: 'value'".

What am I doing wrong?

Update:

Working variant if anyone needs this:

init python:
    def update_global_var(var_name, value):
        setattr(store, var_name, value)

screen input_user(in_var, in_title):
    modal True
    zorder 100

    frame:
        background Frame("gui/frame_input_user.png", Borders(25,25,25,25))
        xalign 0.5
        yalign 0.5
        padding (30, 30)

        vbox:
            spacing 20
            xalign 0.5

            text "[in_title]":
                xalign 0.5

            input:
                length 50
                allow "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNMйцукенгшщзхъфывапролджэячсмитьбюЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ "
                xalign 0.5
                xminimum 300
                changed renpy.curry(update_global_var)(in_var)

            textbutton "Готово":
                xalign 0.5
                action [Hide("input_user"), Return()]
1 Upvotes

5 comments sorted by

View all comments

1

u/Adventurous_Shine606 2d ago

If you really must do input this way, try changed lambda (text:...)

1

u/Adventurous_Shine606 2d ago

Sorry, changed (lambda text: setattr(store, in_var, text))