Well I am building a PyGame in Sublime text, but when I run the batch file to start it I get this error:
Traceback (most recent call last):
File "game.py", line 12, in <module>
player = player("Default", 1, 1, 1)
File "C:\Users\*****\Desktop\RPG\characters\player.py", line 8, in __init__
Character.__init__(self, name, hp)
File "C:\Users\*****\Desktop\RPG\characters\character.py", line 9, in __init__
player.dead = False
NameError: global name 'player' is not defined
Press any key to continue . . .
Now here are my files:
game.py file:
# Main Game File
from characters.player import *
from commands import *
commands = {
'help': help,
'exit': exit
}
player = player("Default", 1, 1, 1)
def isValidCMD(cmd):
if cmd in commands:
return True
return False
def runCMD(cmd, args, player):
commands[cmd](player, args)
def main(player):
while(not player.dead):
line = raw_input(">> ")
input = line.split()
input.append("EOI")
if isValidCMD(input[0]):
runCMD(input[0], input[1], player)
main(player)
player.py file:
# Player Base File
from character import *
class player(Character):
def __init__(self, name, hp, str, int):
Character.__init__(self, name, hp)
self.str = str
self.int = int
and the character.py file:
# Character Base File
class Character(object):
def __init__(self, name, hp):
self.name = name
self.hp = hp
player.dead = False
def attack(self, other):
pass
def update(self):
if self.hp <= 0:
player.dead = True
self.hp = 0
What do I do?