Hello all. I am trying to write a short little game, mainly to boost my knowledge of classes and objects, and of course I am starting to encounter problems.
I have several classes for different types of creatures in this game. Most of them take the form of:
class human:
loc = location()
sta = lifedata()
isplayer = False
nhealth = 20.0
nhunger = 0.0
nenergy = 10.0 - nhunger
nspeed = (((nenergy/10)*7.0) + 3.0)
I can create objects in the shell using these classes and they seem to work quite well, the problem is when I try to create objects in functions:
def creation():
gameplayer = human();
gameplayer.isplayer = True;
goblin1 = goblin();
troll1 = troll();
human1 = human();
bear1 = bear();
This is the result I get:
IDLE 2.6.5
>>> ================================ RESTART ================================
>>>
>>> creation()
>>> goblin1
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
goblin1
NameError: name 'goblin1' is not defined
>>> gameplayer
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
gameplayer
NameError: name 'gameplayer' is not defined
>>>
What am I doing wrong?