0

Hey so I’m writing a text-adventure game in python and made a typingprint function to make the text look like it was typed out. But when I try to use this function with inputs it will reply with None.

import random
import time
import console
import sound
import sys


def typingPrint(text):
    for character in text:
        sys.stdout.write(character)
        sys.stdout.flush()
        time.sleep(0.05)

console.set_color()

typingPrint('Hello! My name is Sawyer and I will be your guide 
throughout this game. Heres a helpful hint, every time you enter
room you will have to battle a enemy.')

time.sleep(3)

player_name = input(typingPrint('\nBefore we begin why don\'t  
you tell me your name: '))

How can I fix this?

  • You need `typingPrint(input("\nBefore we begin why dont you tell me your name: '))`. Also don't assign this to a variable. Your function doesn't `return` anything. – not_speshal Dec 15 '21 at 16:04
  • Switch the places of `typingPrint` and `input`. – MattDMo Dec 15 '21 at 16:04
  • What is your objective? Do you want the `input` prompt to appear as being typed in real time? Or do you want the output of the `typingPrint` function to be passed as `input`? – Sayandip Dutta Dec 15 '21 at 16:09
  • Does this answer your question? [Function returns None without return statement](https://stackoverflow.com/questions/7053652/function-returns-none-without-return-statement) – Random Davis Dec 15 '21 at 16:13

1 Answers1

1

This is because your function doesn't return anything so there is no text in the input prompt. To solve it, you will need to first call your function, then the input -

typingPrint('Hello! My name is Sawyer and I will be your guide throughout this game. Heres a helpful hint every time you enter a room you will have to battle a enemy.')
time.sleep(3)
typingPrint('\nBefore we begin why dont you tell me your name: ')
player_name = input()
sr0812
  • 324
  • 1
  • 9
  • 1
    You could also change `typingPrint` to `return text` at the end, which would allow it to be chained with other statements. – Samwise Dec 15 '21 at 16:15
  • @Samwise, no in this case that wouldn't make sense. Then it would print the text twice. – wovano Dec 18 '21 at 14:37