I'm working on a dungeon styled game, and I made a file called places.py to store the places. I am using a class, then adding attributes to the class. I received an error, and here is the error message:
E0001:invalid syntax (, line 8)
Here would be my code for places.py:
class place(object):
def __init__(self):
self.name=''
self.nearplaces=[]
self.ground=[]
self.monsters=[]
1 = place
1.name='Ruby City'
1.nearplaces=[2,3]
1.ground=[1]
1.monsters=[]
It is confusing how, after declaration, I receive an error when trying to change the attributes. This may be a very simple question, but I wish to know why it does not work, and how to make it work. Thank you.
1 Answer 1
Firstly you cannot use integer literals, like 1, as variable names. This is to avoid ambiguity, so the interpreter knows whether it is looking at a variable or a number (see rules for Python identifiers).
Secondly, to properly instantiate your class you need to use ().
Try:
level_1 = place()
level_1.name='Ruby City'
level_1.nearplaces=[2,3]
level_1.ground=[1]
level_1.monsters=[]
3e2?