Python Text RPG (Part 5) - AWESOME Speech Text Effect - Making the Main Game Loop

preview_player
Показать описание
Welcome to part 5 of our Python Text RPG tutorial! We'll be creating the main game loop, prompting the player for questions to initialize their character, and going over an AWESOME spoken text effect made from an easy little console trick in Python.

Need help debugging? I only reply to subscribers — please ensure you are subscribed ✅ and have the notification bell 🔔 ON!

n this Python Text RPG series, programmer and software engineer Bryan Tong walks you through a beginner-friendly tutorial on building your personalized command-line-based text role playing game in Python. He walks you through concepts such as for loops, while loops, data structures, dictionaries, maps, and even tricky functions like system sleep for text effects.

Рекомендации по теме
Комментарии
Автор

This channel is underrated. Nice tutorial, I really like it. The typewriting effect could be put in a function apart of all the code.
Here is how I would do it:

from sys import stdout
from random import uniform
from time import sleep
# Typewriter effect
def type_writer(text, start=None, stop=None):
if start is None:
start = 0.05
if stop is None:
stop = 0.1
for i in range(len(text)):
stdout.write(text[i])
stdout.flush()
sleep(uniform(start, stop))
return

frenzy
Автор

12:06 When he texts u "hehe ;)"

asdfgasdfg
Автор

Here's my version of the text printing code, as a function.
You can set parameters for the time between each character, and the time between this line and the next. It's called like so:
print_text("\nWe are darkness, waiting for a flame...\n", "normal", "long")

And here 's the function:
def print_text(text, char_wait, line_wait):
#### Time btwn each character ####
if char_wait == "short":
char_wait = 0.01
elif char_wait == "long":
char_wait = 0.2
else:
char_wait = 0.05 #normal

#### Time btwn this line and the next ####
if line_wait == "short":
line_wait = 0.25
elif line_wait == "long":
line_wait = 2
else:
line_wait = 0.5 #normal

#### Writing the line ####

for character in text:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(char_wait)
time.sleep(line_wait)

Note: the text and the variables such as line_wait and char_wait must be strings.
Modify as you like, I hope it helps you. :)

benjamintchang
Автор

Great series of videos! I was already working on a school project building a text RPG and this gave me a lot of ideas to expand upon and now I'm building a more advanced version in my free time.

One question I do have for you is if there could be a helper function for the sys.stdout command? It seems tedious to do this for every string I want the program to give the illusion of typing on screen. I've only been programming for a few days so I honestly don't know how to go about setting a function to import a new variable every time I get to a string I want to print slowly. I would greatly appreciate any suggestions.

FatsFalafel
Автор

I'm very confused about the back and forth usage of either calling the Player class directly or using the variables that took the input. Why not just do one or the other and why did you suddenly call self???

chronicsynths
Автор

You are amazing. Thank you. I have a long text that I try to use textwrap.wrap() function, along with your sys.stdout.write(). but it did not seem to work. May be if you don't mind, you could help me on this one thanks:
for char in
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(.03)

indrasiswanto
Автор

keep getting this error when I try to move: " tuple indices must be integers or slices, not str " in the def player_move (action) section

jdsax
Автор

I keep receiving [pyFlakes] undefined name ' self', and having all of the player stats underlined in red, is ther a work around?.

danilivanov
Автор

hey bryan, we are trying to do a game whit your concept of game, and the game don't run, give an error, can you pls help us, write me, is a work for university

MsTronazo
Автор

When I run the game it works until I type a direction to move and then I get a NameError: name zonemap is not defined.

danc
Автор

Are you not using classes because this tutorial is supposed to be easy? I mean, having an interaction class with all your prints so you just call it once and pass the variable containing the words would make life much easier. Remember to stay D.R.Y. I'm going to be making a tutorial on how to make one of these but with nothing but classes. I've already got 2, 000 lines and the game is almost complete. Using classes makes life so much easier. The inventory part was alot of fun to code. Had to make an inventory class so I can have different types of inventories (like a tattered nap sack, or ruck sack...here was a brain teaser for a minute) and had to make it so the user could see the name of the object in the inventory and also how many they had. So that would take a dictionary with a key value pair of "object name" : #of objects but makes it so the user cannot equip the item because it would be a string so then I had to make a get_object function that looped through all items, matched the object name and returns the object so it can be equipped or something. Don't Repeat Yourself, reusable code with make your life much easier and your code more refined. Plus you can have alot if different items by just instantiating the class with the proper params

thegrowers
Автор

This channel is underrated. Nice tutorial, I really like it. The typewriting effect could be put in a function apart of all the code.
Here is how I would do it:

from sys import stdout
from random import uniform
from time import sleep
# Typewriter effect
def type_writer(text, start=None, stop=None):
if start is None:
start = 0.05
if stop is None:
stop = 0.1
for i in range(len(text)):
stdout.write(text[i])
stdout.flush()
sleep(uniform(start, stop))
return

frenzy
visit shbcf.ru