ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm currently designing a text-based game with Python and I was
wondering if there was a way to "unfold" text in a string one
letter at a time. I wanted to use this for certain dramatic
effect, such as unfolding particular parts of the plotline.
An example would be...
As you move deeper into the darkness of the room, the smell of
death becomes too much to bear.
Instead of this being static and all at once, I want each letter
to be drawn one at a time, one after another.
If this is possible, I'd gratefully appreciate any information
to get this working... also, if it IS possible, is there also a
way to set the pace for scrolling the characters?
Of course you can, just use a loop to print one character at a time, something like:
Code:
for c in some_string:
print c,
delay()
(obviously you want to flesh this out a bit.)
Or if you need to do other stuff while it's printing (e.g. check for input), maybe maintain an index.
Code:
i=0
while whatever_condition:
... do some stuff...
print some_string[i],
i+=1
... do some more stuff...
edit:
Bah, beaten to it, and with a superior implementation.
edit2:
One thing to note, if you expect (hope?) that people will play the game more than once, you might want to add some way to break out of this delay (e.g. pressing escape will break the loop and just print the message), since once you know what to expect, you tend to just want to get on with it. Of course, this depends on how long the message is...
Last edited by smoked kipper; 07-23-2008 at 01:00 PM.
One thing to note, if you expect (hope?) that people will play the game more than once, you might want to add some way to break out of this delay (e.g. pressing escape will break the loop and just print the message), since once you know what to expect, you tend to just want to get on with it. Of course, this depends on how long the message is...
Thank you both for your prompt replies and very helpful information. I was looking all over google for something like this and I just didn't know quite how to word it, many thanks.
Quote:
Originally Posted by smoked kipper
edit2:
One thing to note, if you expect (hope?) that people will play the game more than once, you might want to add some way to break out of this delay (e.g. pressing escape will break the loop and just print the message), since once you know what to expect, you tend to just want to get on with it. Of course, this depends on how long the message is...
Also, smoked kipper, that second note will be good to keep in mind, definitely. The main goal of designing this game is to apply knowledge gained from this new language to a fun and engaging project, and as I learn more, I will go back and tweak it until, well, I'm happy with it, and... it's fun to play.
The ability to skip through dialogue is a feature no good game should do without. User freedom is paramount.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.