Click here to Skip to main content
15,565,747 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is the code:
Python
class Race(Sentient):
    def __init__(self, special_abilites={}, Race_Strength=0, Race_Dexterity=0, Race_Constitution=0, Race_Intelligence=0, Race_Wisdom=0, Race_Charisma=0, speed=0):
        self.special_abilites = special_abilites
        self.Race_Strength = Race_Strength
        self.Race_Dexterity = Race_Dexterity
        self.Race_Constitution = Race_Constitution
        self.Race_Intelligence = Race_Intelligence
        self.Race_Wisdom = Race_Wisdom
        self.Race_Charisma = Race_Charisma
        special_abilites = {}

Darkvision = ("None", False)
Stonecunning = ("None", False)
Stability = ("None", False)
Poison_Resistance = ("None", False)
Spell_Resistance = ("None", False)
Goblinfoe = ("None", False)
Giantfoe = ("None", False)

Human = Race(None,1,1,1,1,1,1, speed=30)
Dwarf = Race(special_abilites={Darkvision:1,Stonecunning:2,Stability:3,Poison_Resistance:4,Spell_Resistance:5,Goblinfoe:6,Giantfoe:7})

if Darkvision in special_abilites:
    Darkvision = ("You can see 60ft in the darkness", True)
if Stonecunning in special_abilites:
    Stonecunning = ("You can notice unusual stonework", True)
if Stability in special_abilites:
    Stability = ("You are much harder to topple", True)

It gives this when run:
Python
Traceback (most recent call last):
  File "DnD game engine.py", line 149, in <module>
    if Darkvision in special_abilites:
NameError: name 'special_abilites' is not defined


I don't know if it's something simple I haven't caught or something else, any help is appreciated. Thanks!

What I have tried:

Looking over the code and finding solutions in google
Posted
Comments
Mike Hankey 20-Oct-22 14:00pm    
I don't know much about python so I'll make a SWAG and say;

if Darkvision in self.special_abilites:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900