因此,對於我的第一個大型python項目,我正在構建一個基於文本的遊戲。它應該是模塊化的,故事和項目等可以編輯並替換爲實際源代碼的少量編輯。基本上,用戶命令存儲爲一個立即分解爲列表的字符串。第一個元素是像'檢查'這樣的動作,第二個元素是像「位置」或「項目」那樣的動作的僞參數。在解釋命令後,它會進入名爲'item_or_loc'的執行模塊。在這裏,我得到錯誤。誰能幫忙?如果它能提供幫助,我會提供更多信息或整個源代碼。Python TypeError:'NoneType'類型的參數不可迭代
命令模塊:
def item_or_loc(iolo):
if iolo in items.items_f():
print (items.iolo(1))
elif iolo in locations.locations_f():
print (locations.iolo(1))
else:
print ('Command not recognized, try again.')
def location(loco):
plo_l = PlayerClass #(player location object_location)
if loco == 'location':
plo_l.player_loc(0)
def abort(abo):
sys.exit()
def inventory(invo):
pio_i = PlayerClass #(player inventory object_inventory)
if invo == 'inventory':
pio_i.player_inv(0)
項目模塊:
patient_gown=('Patient gown', 'A light blue patient\'s gown.')
wrench=('Wrench','')
stick=('Stick','')
prybar=('Prybar','')
screwdriver=('Screwdriver','')
scalpel=('Scalpel','')
broken_tile=('Broken tile','')
hatchet=('Hatchet','')
janitor_suit=('Janitor suit','')
位置模塊:基本上一樣的項目模塊
播放器模塊:
import items
import locations
class PlayerClass:
def player_inv(inv_index):
pinventory = [items.patient_gown[inv_index]]
print (pinventory)
def player_loc(loc_index):
ploc = [locations.cell[loc_index]]
print (ploc)
以源代碼的形式提供更多上下文會非常有幫助。這很難幫助你。 – 2012-04-13 21:38:39
你想要多少錢?整個command.py模塊? – SciurusDoomus 2012-04-13 21:39:08
至少要說明「物品」來自何處。 – 2012-04-13 21:39:34