Page 1 of 1

Type out predetermined word when player types?

Posted: Mon Aug 16, 2021 4:13 am
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

Re: Type out predetermined word when player types?

Posted: Mon Aug 16, 2021 5:42 am
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...

Re: Type out predetermined word when player types?

Posted: Mon Aug 16, 2021 7:14 pm
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

Re: Type out predetermined word when player types?

Posted: Tue Aug 17, 2021 6:44 am
by Remix
We'd need to see the code you are trying and the error message...

Re: Type out predetermined word when player types?

Posted: Fri Apr 19, 2024 7:22 am
by Andredron
Awesome! Been looking for something like this to create a screen by hacker man type, http://tentaculus.ru/hackerman/