Python Text-Based Rpg Tutorial Part 2 - Setting up the Game

preview_player
Показать описание

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

@James Berry instead of
defining the init function like:
def init(self, name):

it needs to look like:
def __init__(self, name):

there are two underscores in front of init and
two underscores after it. It's pretty important that
it looks exactly like that. I now realize that I didn't
explain that part in the video.

vincentgizzarelli
Автор

cool tutorials. I've been working on a text rpg for a while but watching this definitely taught me so much more I could implement :). Thanks man.

modernmistyk
Автор

Hello. I'm a beginner, and its the first time I see the %s and %.
It basically does the same as the 'Hi, my name is {}'.format(player.name), for example?

raphaelmacedo
Автор

Neither 'cls' nor 'clear' seems to work in my Windows 10 Pc using Python 2.7.13

Edit: But I noticed that when I just double click the .py file and let it run in Python instead of in Idle it does work. It's just in the Idle Console thingy that it doesn't work. And apparently I'm not the only one for whom this does not work, but I guess the cls command itself does work. Just a little bug in Idle. Hope this helps somebody.

OttosTheName
Автор

For some reason, my code doesn't work, the error message is saying "maxhealth is not defined".
Is it because I'm running it on python 3?

This is my code:
import sys
import os


class Player:
def __init__(self, name):
self.name = name
self.maxhealth = 100
self.heatlh = self.maxheatlh
self.attack = 10
def main():
print ("Welcome to the World of [Inset Name Here]\n 1.)Start\n 2.)Load\n 3.)Exit")
option = input("-> ")
if option == "1":
start()
elif option == "2":
pass
elif option == "3":
print("BYEEE")
sys.exit()
else:
print ("Error, that is not an option")
def start():
print ("Hello, what is your name?")
option = input("-> ")
global PlayerIG
PlayerIG = Player(option)
start1()

def start1():
print ("Hello %s are you ready? If your not, then get ready" % PlayerIG.name)

main()

calamitycow
Автор

I've been have serious problems with the name function. everytime I enter a name it gives
me this:

Traceback (most recent call last):
File Inc..py", line 62, in <module>
customs()
File Inc..py", line 44, in customs
name()
File Inc..py", line 55, in name
name1()
File Inc..py", line 58, in name1
print ("%s" % PlayerIG.name)
AttributeError: 'Player' object has no attribute 'name'

PilgrimTheEmbraced
Автор

How are you able to call start before defining it? Im trying to follow along but Im getting a "name start is not defined" error.

daguchful
Автор

For the def main and def start st the bottom where it has that it loops the code

Slimbo
Автор

I use python3, it tells me that there is something wrong in the print("1.) Start"), please help


import sys
import os

class Player:
def __init__(self, name):
self.name = name
self.maxhealth = 100
self.health = self.maxhealth
self.attack = 10
self.defense = 4

def main():
os.system("clear")
print("Welcome to my game!")
print("1.) Start")
print("2.) Load")
print("3.) Exit")
option = input("-> ")
if option == "1":
start()
elif option == "2":
pass
elif option == "3":
sys.exit()
else:
main()

def start():
os.system('clear')
print("Enter name")
option = input("-> ")
PlayerIG = Player(option)
start1()

picheon
Автор

I know these are old videos - sorry for bugging you about old content haha.
What is the difference between the "input()" function and the "raw_input()" function?

XIsleTheWanderer
Автор

This should be a no brainer as I realise this is a fairly old tutorial. But do you have any idea what went wrong here? Your code is identical to mine but python 3.7 doesn't want to accept that i've defined PlayerIG already.

Traceback (most recent call last):
File "U:/CS160 Programs/rpg part 1.py", line 50, in <module>
main()
File "U:/CS160 Programs/rpg part 1.py", line 23, in main
start() #calls upon start game function
File "U:/CS160 Programs/rpg part 1.py", line 39, in start
print(PlayerIG)
NameError: name 'PlayerIG' is not defined

famas
Автор

What's the difference between using '"Something" % string' and '"Something else" + another string'?

pianogoat
Автор

when i run it is says start referenced before assignment
please help

mcsalty
Автор

Hey +Cryptero . I am enjoying this tutorial dude! I have an issue. i am on windows and the os.system('cls') does not clear the console for me. instead, i get a little up arrow icon and everything is still cluttered. please help. thanks. or anyone else in the comments, that would be greatly appreciated.

legitchrisv
Автор

i can play the game up to the point in which i put in my name, at which point, after putting in a name, this pops up.:

Traceback (most recent call last):
File Game 1/Game1.py", line 42, in <module>
main()
File Game 1/Game1.py", line 19, in main
start()
File Game 1/Game1.py", line 32, in start
PlayerIG = Player(option)
TypeError: this constructor takes no arguments


what did i do wrong?

sparticusthespartan
Автор

What is the difference between input() and raw_input() ?

craftman
Автор

I followed up to 4:10 with the same code in cloud9 but I couldn't get it to work:

import sys
import os

class Player:
def _init_(self, name):
self.name = name;
self.maxhealth = 100
self.health = self.maxhealth
self.attack = 10

def main():
print "Welcome to the dungeon!"
print "1} - Start"
print "2} - Load"
print "3} - Exit"
option = raw_input("--> ")
if option == "1":
start()
elif option == "2":
pass
elif option == "3":
sys.exit()
else:
main()

def start():
print "Hello! What is your name?"
option = raw_input("--> ")
global PlayerIG
PlayerIG = Player(option)
start1()

def start1():
print "Hello %s how are you?"%PlayerIG.name



main()

iamspeciol
Автор

when i do os.system('clear') it doesn't clear it

oyahmahah
Автор

invalid charectar in identifier pls help
python:3.4.2
code:
import sys
import os

class Player:
def __init__(self, name):
self.name = name;
self.maxhealth = 100
self.health = self.maxhealth
self.attack = 10

def main():
os.system('cls')
print ("Welcome to the dungeon!")
print ("1} - Start")
print ("2} - Load")
print ("3} - Exit")
option = raw_input("--> ")
if option == "1":
start()
elif option == "2":
pass
elif option == "3":
sys.exit()
else:
main()

def start():
os.system('cls')
print ("Hello! What is your name?")
option = raw_input("--> ")
global PlayerIG
PlayerIG = Player(option)
start1()

def start1():
os.system('cls')
print ("Hello %s how are you?"%PlayerIG.name)



main()

xXninjaXx
Автор

having a problem with my else statments

gabecimoch
visit shbcf.ru