How to get Player's input within Screen?

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
appleponycmh
Newbie
Posts: 2
Joined: Sat Mar 16, 2019 12:56 pm
Contact:

How to get Player's input within Screen?

#1 Post by appleponycmh »

Hi. I'm kind of new with using RenPy and i recently try to learn Python itself from the very begining (also i'm not a good English speaker),
but i would be glad if i could get some help with my code.

I'm trying to create a game which is somewhat between genre of 'professor latyon' and some web-puzzle-type thing

The problem that i am having right now is
If you think of the game 'professor layton', when you press the 'input answer' button,
you would reach another screen which you could input your answer.

similarly, i would like the player to input a certain 'word' so to check their answer
for the input method, i want them to use their keyboard to submit the answer

so looking through some tutorials i guess using renpy.input would give a keyboard input?
but i think i was struggling at some various situations and tried different things

such as

first i tried to call a label (which has renpy.input in it) within the screen,
but after the label it skips the after screen statements(?) which i was not intended to work that way

so i search how to use a user-created functions(?) and tried to put the renpy.input() inside the function i created
and call the function using "action Function()" thing that is used in Screens,
however, I've got this error,

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 12, in script
    call screen InputAnswerTypeWord
  File "renpy/common/000statements.rpy", line 519, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "renpy/common/00action_other.rpy", line 517, in __call__
    rv = self.callable(*self.args, **self.kwargs)
  File "game/script.rpy", line 4, in Inputing_AnswerType_Word
    InputType_Word = renpy.input("Input Your Answer")
Exception: Cannot start an interaction in the middle of an interaction, without creating a new context.

here is the code i used is this:

Code: Select all

init -1 python:
    def Inputing_AnswerType_Word():
        global InputType_Word
        InputType_Word = renpy.input("Input Your Answer")
        InputType_Word = InputType_Word.strip()

label start:
    default InputType_Word = ""
    default Answer_Player = ""

    "This is the start of the game"
    call screen InputAnswerTypeWord
    "You have answered, [Answer_Player]"

screen InputAnswerTypeWord():

    modal True

    timer 0.0001 action SetVariable("InputType_Word", "")
    
    frame:
        textbutton "Input":
            action Function(Inputing_AnswerType_Word)
        align(.5, .5)

    frame:
        textbutton "Confirm":
            action [
                SetVariable("Answer_Player", InputType_Word),
                Hide("InputAnswerTypeWord"),
                ]
        align(.4, .6)
    
    frame:
        textbutton "Go Back":
            action [
                Hide("InputAnswerTypeWord"),
                Hide("ButtonOfNumbersInput")
                ]
        align(.6, .6)

    text "[InputType_Word]":
        
        align(.5,.8)

I searched about the error and found some of the advices,
but i believe this time i have failed to understand what it means of the terms of
"starting an interaction" and "creating a new context" means.


The Other option that i have tried to do is using

Code: Select all

screen input2:
    window:
        style "nvl_window" 
        input id "input" xalign 0.5 yalign 0.5 
this thing...
which i have no idea what this does,
but i am slightly dissatisfied because of two things
1. If i press the Enter key when the input is in progress,
it just ends the current Screen and having the same problem which i have mention earlier
2. So I tried to make a new button which allows to continue to use the screen properties without getting out of the screen
however, I couldn't find a way to disable the Enter key (or at least i didn't understand some of the code)


==============================================================================================

To sum up my Question,

How can i use the .input command properly within screen and get that answer to save in some variable?
in this case, if player press "Input" : player would give an input via keyboard
Then, text "[InputType_Word]": will display the inputed answer
then, if pressed "Confirm": the answer(InputType_Word) will be equal to (Answer_Player)

OR

if using the style "nvl_window" method, is there a way to disable the Enter key?

As an alternative, if disabling the Enter key throughout the whole gameplay is possible, i think using "nvl_window" method would work perhaps?

sry of me laying down a bunch of questions, but i do think there are some various method to solve this kind of matter,
so i would like to learn some new coding ways which i may used in the future

thanks for reading

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: How to get Player's input within Screen?

#2 Post by Per K Grok »

appleponycmh wrote: Sat Mar 16, 2019 1:55 pm
The problem that i am having right now is
If you think of the game 'professor layton', when you press the 'input answer' button,
you would reach another screen which you could input your answer.

similarly, i would like the player to input a certain 'word' so to check their answer
for the input method, i want them to use their keyboard to submit the answer

To have an input function in a screen you can do something like this

Code: Select all

default inputText = ""

init python:
    def input_func(newstring):
        store.inputText = newstring

screen input():
    frame:
        pos (100,100)
        maximum (200,80)
        text "Enter text and push return:"
        input changed input_func ypos 15
        text "Output: " + inputText ypos 30

label start:
    scene YourScene
    show screen input


appleponycmh
Newbie
Posts: 2
Joined: Sat Mar 16, 2019 12:56 pm
Contact:

Re: How to get Player's input within Screen?

#3 Post by appleponycmh »

I think i managed to solve some problems. Many thanks for your help! :D

Quite not fully understood the whole code though but
i think i manage to make some progress using the code that you provided
now the game does not skip ahead when press the Enter key just as i wanted.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot], voluorem