Type out predetermined word when player types?

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
AliceGames
Newbie
Posts: 13
Joined: Fri Jul 23, 2021 10:06 am
Contact:

Type out predetermined word when player types?

#1 Post by AliceGames »

The title is weird, but basically I want to make it to where it asks the player to input a word, I.E. in my game I want the player to be forced to type out "A date" when the character asks them why they are there. He is in control of the player, is what im trying to do.
I want it to be when the player hits any random key it types out one letter of the phrase.
I hope this makes sense, I dont know where else to look for help lol

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Type out predetermined word when player types?

#2 Post by hell_oh_world »

You can try this.

Code: Select all

init python:
  import string

screen fixed_input(input):
  default current_input = []
  default input_ = list(input)
  default keysyms = tuple("keyup_{}".format(l) for l in string.ascii_letters + string.digits)
  
  if input_:
    key keysyms:
      action Function(current_input.append, input_.pop(0))
      
  if current_input:
    key "input_backspace" action Function(input_.insert, 0, current_input.pop(-1))
    
  key "input_enter" action Return()
  
  text "".join(current_input)

Code: Select all

label start:
  call screen fixed_input("A date")
This only responds to any alphabet letter and digit. If you want to capture all the keys on the keyboard, might be better to do this inside a CDD instead.
Another option that I could think of...

Code: Select all

init -1509 python:
    @renpy.pure
    class FixedInputValue(InputValue, FieldEquality):
        identity_fields = [ "input", "target_input" ]
        equality_fields = [ "returnable" ]

        def __init__(self, input, target_input, default=True, returnable=False):
            self.default = default
            self.returnable = returnable

            self.input = input
            self.target_input = target_input

        def get_text(self):
            return "".join(self.input)

        def set_text(self, value):
            self.input.clear()
            self.input += self.target_input[:len(value)]
            renpy.restart_interaction()

Code: Select all

screen fixed_input(input):
    default input_ = []
    default fixed_input_value = FixedInputValue(input_, input)
    
    input:
        value fixed_input_value

Code: Select all

label start:
  call screen fixed_input("A date")
This should respond to any key I guess...

AliceGames
Newbie
Posts: 13
Joined: Fri Jul 23, 2021 10:06 am
Contact:

Re: Type out predetermined word when player types?

#3 Post by AliceGames »

hell_oh_world wrote: Mon Aug 16, 2021 5:42 am You can try this.

Code: Select all

init python:
  import string

screen fixed_input(input):
  default current_input = []
  default input_ = list(input)
  default keysyms = tuple("keyup_{}".format(l) for l in string.ascii_letters + string.digits)
  
  if input_:
    key keysyms:
      action Function(current_input.append, input_.pop(0))
      
  if current_input:
    key "input_backspace" action Function(input_.insert, 0, current_input.pop(-1))
    
  key "input_enter" action Return()
  
  text "".join(current_input)

Code: Select all

label start:
  call screen fixed_input("A date")
This only responds to any alphabet letter and digit. If you want to capture all the keys on the keyboard, might be better to do this inside a CDD instead.
Another option that I could think of...

Code: Select all

init -1509 python:
    @renpy.pure
    class FixedInputValue(InputValue, FieldEquality):
        identity_fields = [ "input", "target_input" ]
        equality_fields = [ "returnable" ]

        def __init__(self, input, target_input, default=True, returnable=False):
            self.default = default
            self.returnable = returnable

            self.input = input
            self.target_input = target_input

        def get_text(self):
            return "".join(self.input)

        def set_text(self, value):
            self.input.clear()
            self.input += self.target_input[:len(value)]
            renpy.restart_interaction()

Code: Select all

screen fixed_input(input):
    default input_ = []
    default fixed_input_value = FixedInputValue(input_, input)
    
    input:
        value fixed_input_value

Code: Select all

label start:
  call screen fixed_input("A date")
This should respond to any key I guess...
So I tried the top code, but it didnt type out anything when I pressed keys, the second code gives me a syntax error

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Type out predetermined word when player types?

#4 Post by Remix »

We'd need to see the code you are trying and the error message...
Frameworks & Scriptlets:

User avatar
Andredron
Miko-Class Veteran
Posts: 722
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: Type out predetermined word when player types?

#5 Post by Andredron »

Awesome! Been looking for something like this to create a screen by hacker man type, http://tentaculus.ru/hackerman/

Post Reply

Who is online

Users browsing this forum: Bing [Bot], DewyNebula