2015-01-03 43 views
-2

試着創建一個dnd角色:繼續獲取:TypeError:get_stats()只需要1個參數(0給定)。我不知道如何給殼體提供什麼。TypeError:get_stats()只需要1個參數(0給出)

繼承人的代碼:

import random 

class Character(object): 

     def __init__(self,name): 

     self.name = raw_input('name') 

     # Attributes for Pathfinder 
     def get_stats(self): 
      stats = [] 
      count = 0 
      while count < 6: 
       roll = [] 
       roll = [random.randint(1,6) for x in range(4)] 
       roll = sorted(roll) 
       del(roll[0]) 
       sum = 0 
       for x in roll: 
        sum += x 
       stats.append(sum) 
       count += 1 


      print stats 
      return stats 

     stats = get_stats() 
     ste = stats[0] 
     con = stats[1] 
     dex = stats[2] 
     inte = stats[3] 
     wis = stats[4] 
     cha = stats[5] 

     #Modifiers 
     stemod = (ste - 10)/2 
     dexmod = (dex - 10)/2 
     conmod = (con - 10)/2 
     intemod = (inte - 10)/2 
     wismod = (wis - 10)/2 
     chamod = (cha - 10)/2 

     #Bios 
     #Sex 

     sex = random.randint(1,2) 
     if sex == 1: 
      sex = "male" 
     else: 
      sex = "female" 

     #Races and size 
     #list_of_races 
     x = random.randint(1,7) 
     if x == 1: 
      race = 'drawf' 
      size = 'med' 
      con += 2 
      wis += 2 
      cha -= 2 
     elif x == 2: 
      race = 'elf' 
      size = 'med' 
      dex += 2 
      inte += 2 
      con -= 2 
     elif x == 3: 
      race = 'human' 
      size = 'med' 
      bonus = random.randint(1,6) 
      if bonus == 1: 
       ste += 2 
      elif bonus == 2: 
       con += 2 
      elif bonus == 3: 
       dex += 2 
      elif bonus == 4: 
       inte += 2 
      elif bonus == 5: 
       wis += 2 
      elif bonus == 6: 
       cha += 2 
     elif x == 4: 
      race = 'halfling' 
      size = 'small' 
      dex += 2 
      cha += 2 
      ste -= 2 
     elif x == 5: 
      race = 'gnome' 
      size = 'small' 
      con += 2 
      cha += 2 
      ste -= 2 
     elif x == 6: 
      race = 'half-elf' 
      size = 'med' 
      bonus = random.randint(1,6) 
      if bonus == 1: 
       ste += 2 
      elif bonus == 2: 
       con += 2 
      elif bonus == 3: 
       dex += 2 
      elif bonus == 4: 
       inte += 2 
      elif bonus == 5: 
       wis += 2 
      elif bonus == 6: 
       cha += 2 
     elif x == 7: 
      race = 'half-orc' 
      size = 'med' 
      bonus = random.randint(1,6) 
      if bonus == 1: 
       ste += 2 
      elif bonus == 2: 
       con += 2 
      elif bonus == 3: 
       dex += 2 
      elif bonus == 4: 
       inte += 2 
      elif bonus == 5: 
       wis += 2 
      elif bonus == 6: 
       cha += 2 

     #Size pelenties 




     #Classes 
     # List of classes(Fighter,Ranger,Wizard,Cleric) 
     c = random.randint(1,4) 
     playclass = '' 
     while playclass == '': 
      if c == 1 and ste > 10: 
       playclass = 'Fighter' 
       hp = 10 + conmod 
       bab = 1 
       fort_save = 2 + conmod 
       reflex_save = 0 + dexmod 
       will_save = 0 + wismod 
      elif c == 2: 
       playclass = 'Ranger' 
       hp = 10 + conmod 
       bab = 1 
       fort_save = 2 + conmod 
       reflex_save = 2 + dexmod 
       will_save = 0 + wismod 
      elif c == 3 and inte > 10: 
       playclass = 'Wizard' 
       hp = 6 + conmod 
       bab = 0 
       fort_save = 0 + conmod 
       reflex_save = 0 + dexmod 
       will_save = 2 + wismod 
      elif c == 4 and wis > 10: 
       playclass = 'Cleric' 
       hp = 8 + conmod 
       bab = 0 
       fort_save = 2 + conmod 
       reflex_save = 0 + dexmod 
       will_save = 2 + wismod 
      else: 
       c = random.randint(1,3) 

     #AC 
     ac = 10 + dexmod 
     if size == 'small': 
      ac += 1 


     print sex 
     print size +" "+race 
     print 'strenght : ' + str(ste) 
     print 'constitution : ' + str(con) 
     print 'dexterity : ' + str(dex) 
     print 'intelligence : ' + str(inte) 
     print 'wisdom : ' + str(wis) 
     print 'charisma : ' + str(cha) 
     print playclass 
     print 'HP:' + str(hp) 
     print 'AC:' + str(ac) 
     print 'BAB:' + str(bab) 
     print 'Fort:' + str(fort_save) 
     print 'Will:' + str(will_save) 
     print 'Reflex:' + str(reflex_save) 
+0

特定於實例的初始化必須在'__init__'中發生。具體來說,這裏的調用不起作用,因爲你正在有效地調用'Character.get_stats'。 – dom0

+0

這解釋了爲什麼它會立即顯示結果,而不是等待我輸入一個輸入 –

回答

0

在你get_stats()功能,你已經把self。但是填補了括號中的行:

stats = get_stats() 

你應該把None在你的括號來防止錯誤。所以該行看起來像:

stats = get_stats(None) 

爲什麼添加None?這意味着除self以外的其他缺陷的數量是0或None。我希望這可以幫助你!

+0

我從來不會想到會看到那裏。 –

相關問題