私の最初の大きなpythonプロジェクトでは、テキストベースのゲームを構築しています。物語やアイテムなどを編集して置き換えて、実際のソースコードをほとんど編集しないように、モジュール化されているはずです。基本的には、userコマンドは文字列として格納され、すぐにリストに分割されます。最初の要素は 'inspect'のようなアクションで、2番目の要素は 'location'や 'item'のようなアクションの疑似引数です。コマンドが解釈された後、それは '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)
ソースコードの形でより多くのコンテキストを提供することは非常に役に立ちます。これだけであなたを助けるのは難しいです。 –
どれくらいお望みですか? command.pyモジュール全体? – SciurusDoomus
少なくとも 'items'がどこから来ているのかの説明。 –