Well here's a weird question. I am making an RPG game in python 3.6 and I want the name of my bad guy to be very ominous, and I thought of having his name look like this (the spam thing not the other Minecraft stuff) for the record, Minecraft has nothing to do with this, it was the only thing I could find as an example for what I'm looking for. All help is appreciated thanks!
Asked
Active
Viewed 57 times
0
-
1This is not a question. What do you want to do? – ForceBru Nov 04 '17 at 19:01
-
@ForceBru I want to know how to make my bad guy's name look like the spam of letters in the gif I provided. as in print("(spam of letters): Do you think you can stop me?") – Aidan Christopher Nov 04 '17 at 19:12
-
Ah, so, you need to learn how to generate random letters (Google this) and concatenate them into a single string (so simple there's no need for Google). If you want to make a row of flashing random strings like in the gif, you also need a basic loop, which is fairly simple to do. – ForceBru Nov 04 '17 at 19:16
-
Are you making a command line game, or a GUI game? – Imperishable Night Nov 04 '17 at 20:39
-
@ImperishableNight command line. its also a multiple choice kinda game like the way telltale does it – Aidan Christopher Nov 04 '17 at 20:45
-
Then you need to constantly overwrite the name with different random characters, which requires some terminal control. Try [curses](https://docs.python.org/3/library/curses.html). – Imperishable Night Nov 04 '17 at 20:47
-
@ImperishableNight I'm extremely new to python, can you give me an example on what you mean? I've never used curses – Aidan Christopher Nov 04 '17 at 20:52
-
To be honest, neither do I (with curses), but I know that your problem doesn't exactly have much to do with python. It has more to do with the terminal: normally, you can only print strings after strings in the terminal, not change strings you've previously printed (you can rewrite the current line with `\r`, but even that is probably platform-dependent). There are advanced terminal control codes, but they are more obscure and definitely platform-dependent. Curses is a convenient interface to help you figure out what control codes to send to the terminal. – Imperishable Night Nov 04 '17 at 21:03
-
@ImperishableNight I'm using pycharm by the way if that changes anything – Aidan Christopher Nov 04 '17 at 21:49
-
PyCharm probably doesn't help because it's just an IDE, not a runtime library. However, it may cause some [problems with debugging](https://stackoverflow.com/questions/17008372/pycharm-how-to-launch-for-a-standard-terminal-to-solve-an-issue-with-curses). – Imperishable Night Nov 04 '17 at 22:32
-
@ImperishableNight So what do you think I should do? Do you think it's worth the hassle? – Aidan Christopher Nov 04 '17 at 22:42
-
It's probably not worth it in the short term, but if you can learn curses, it will probably prove very helpful to command line game programming, as you can then do so much beyond just printing strings. – Imperishable Night Nov 04 '17 at 22:56
-
@ImperishableNight thanks for the advice, I’ll go learn curses – Aidan Christopher Nov 05 '17 at 02:13
1 Answers
0
An example to output random ascii characters in the terminal.
import random,string,sys,time
name_length = 10 # 10 characters for a name
randomize_duration = 10 # 10 seconds
sleep_time = 0.1 # delay time
total_time = 0
while(total_time < randomize_duration):
chars = []
for i in range(name_length):
chars.append(random.choice(string.ascii_letters))
randName = ''.join(chars)
sys.stdout.write("%s >\r" % (randName))
time.sleep(sleep_time)
total_time += sleep_time
sys.stdout.flush()
Please note that this is a blocking call. i.e the code will wait for the while loop to complete. This is just to give you an example using sys.stdout.flush call.

Ajjo
- 234
- 1
- 11