ユーザーがコマンドを入力するPythonで「ゲーム」を作ろうとしていました。ただし、その入力を関数名として使用できるかどうかはわかりません。これは私の現在の努力です:
def move():
print("Test.")
if __name__ == "__main__":
input("Press enter to begin.")
currentEnvironment = getNewEnvironment(environments)
currentTimeOfDay = getTime(timeTicks, timeOfDay)
print("You are standing in the {0}. It is {1}.".format(currentEnvironment, currentTimeOfDay))
command = input("> ")
command()
ここで、入力は move でした。これは、(潜在的なエンド ユーザーがそうするかもしれないように) その関数を呼び出そうとしたからです。ただし、次のエラーが表示されます。
Traceback (most recent call last):
File "D:\Text Adventure.py", line 64, in <module>
command()
TypeError: 'str' object is not callable
プログラムが「移動」関数を呼び出すことで実現する、ユーザーがゲーム内で「移動」できるようにする方法があるかどうか疑問に思っていました。