私はPythonを学んでおり、文字のホットゾーンに基づいて創傷システムを作成しようとしています。ここに私が書いたことがあります。あまりにも私を判断しないでください。私はskin_cut入力のために期待するPython:クラスメソッド内の変数
class Character:
def __init__ (self, agility, strength, coordination):
self.max_agility = 100
self.max_strength = 100
self.max_coordination = 100
self.agility = agility
self.strength = strength
self.coordination = coordination
def hit (self, hit_region, wound):
self.hit_region = hit_region
self.wound = wound
#Hit Zones
l_arm=[]
r_arm=[]
l_leg=[]
r_leg=[]
hit_region_list = [l_arm , r_arm, l_leg, r_leg]
#Wound Pretty Names
healthy = "Healthy"
skin_cut = "Skin Cut"
muscle_cut = "Muscle Cut"
bone_cut = "Exposed Bone"
hit_region.append(wound)
john = Character(34, 33, 33)
john.hit(l_arm, skin_cut)
は「スキンカット」として認識されるように、その後、私はリストとして定義され、l_armに追加されました。しかし、私は常に名前のエラーを取得します(l_armは定義されていません)。私が最初の引数として 'wound'を使ってメソッドを書き直すと、Name Errorに定義されていない 'wound'が現れます。そのようなことは、私が逃したクラスの構造に何かがあると言いますが、私は何が分からないのですか。
ローカル変数。 l_armは、関数の実行が終了すると破棄されます。 – 7stud
エラーを提示してください。 – Nilesh
@Lafada、明らかです! – 7stud