0

First, look at this:

import time

wait = time.sleep

def put(char):
    print(char, end='')

def text(*pieces):
    for p in pieces:
        for c in p:
            put(p)
            wait(0.25)

I wanted to make a function that prints characters one by one with a delay of 250ms. But the problem is, it doesn't actually print characters one by one, instead, nothing happens until the "for" loop ends, then the given pieces of text is printed directly at once. Can someone tell me another way to do that, as in Undertale, typing/printing/putting characters one by one with a delay? Thanks.

1 Answers1

1

You need to add flush=True to your print statement, otherwise the system will wait till the for loop is done. Note: this is only done if you're printing with end=''.

wait = time.sleep

def put(char):
    print(char, end='', flush=True)

def text(pieces):
    print(pieces)
    for p in pieces:
        put(p)
        wait(0.25)

text('arsasrtrasars')
Joost
  • 3,609
  • 2
  • 12
  • 29