This is somewhat related to my previous post requesting assistance for code that would unfold text char by char to give that movie-like intro and plotline sequencing to my text-based game.
Borrowing from Rocket357's code I have the following:
Code:
def unfold_message(msg,delay):
try:
delay=float(delay)
except ValueError:
delay=0.100
for char in msg:
time.sleep(delay)
sys.stdout.write(char)
sys.stdout.flush()
print
This worked out perfectly, exactly what I was looking for (thanks again
)
However, I also took smoked kipper's advice in offering the user a way to "fast forward" through the scrolling, in the case of them having already read those parts and just wishing to get into the game again...
However I am having trouble with implementing user input (say to have the user press the enter button to instantly speed the scrolling) the way I want it to work.
I've tried many different ways, and some have come closer to others, my most recent attempt is this:
Code:
def unfold_message(msg,delay):
x = True
if x == True:
try:
delay=float(delay)
except ValueError:
delay=0.100
for char in msg:
time.sleep(delay)
sys.stdout.write(char)
sys.stdout.flush()
print
else:
x = bool(raw_input())
if x == False:
clear()
print msg
Not my best, but... my most recent
.
I want to be able to have the user hit enter without stopping the scrolling with a prompt for him/her to do so.
However I seem to implement it, the scrolling will always STOP, and then wait for the user's raw_input() and then will either print the whole msg, or just break up the scrolling text into smaller chunks.
I know it's something elegant and simple that is required, but I just can't seem to find it. Am I using the wrong control statements? I have tried if statements, for statements, while statements.
Somewhat still new to this, so help is definitely appreciated...
Thanks for your time,
x.D