Pyautoguiで「Graal Online Classic」と呼ばれるMMO用のボットを作成しようとしています。それは彼らにメッセージを送るプレーヤーの "PM"を読んでから、適切な応答で返信します。また、プレイヤー名のスクリーンショットを取得し、それをtesseractの文字列に変換して辞書に格納し(そしてその特定のプレーヤーがボットのレスポンス階層内にある場所を保存する)、それを使ってプレイヤーがメッセージしたかどうかを判断するそれらの前に。辞書のキーのテスト
def player_id(name_coords, option): # Indentifies person who messaged and depending on if this person has messaged before changes response
players = {} # Used to store players names and where in the response is
keys = players.keys()
image = pyautogui.screenshot('name_test.png', region = name_coords) # Names are screenshots
name_image = str(pytesseract.image_to_string(Image.open('name_test.png')))
print(name_image)
for name_image in keys:
print("User is previous user.")
if players[name_image] == None:
players[name_image] = option
else:
players[name_image] = players[name_image] + option
return players[name_image]
else:
print("User was not previously found, adding to dictionary.")
players[name_image] = None
print(players.keys())
print(players)
上記の機能に問題があります。前にそれらを伝えた人が見つかると、if文に行きますが、何があってもelse文が代わりに実行されます。プレイヤーが2回目のメッセージを送ってもキーのname_imageのメッセージを表示しても、値はプレーヤーと同じに表示されますが、それでもfalseが返されます。ここでhttps://pastebin.com/haJRfqJD
を必要に応じて、ここで
は完全なコードであるあなたが、ここでループのための必要はありません3つのメッセージ
None
(454, 222)
Found a waiting message
Found an open message
1003 424
Player messaged 1
1
I hate sand
User was not previously found, adding to dictionary.
dict_keys(['I hate sand'])
{'I hate sand': None}
The bounty quest allows you to hunt mobs for cash! Location: Castle, steward's room(to the right in the throne room) [PM 1 for specifics, PM 2 for TIPS, PM 3 for possible bounties]
Replying...
(454, 222)
Found a waiting message
Found an open message
1003 424
Player messaged 1
1
I hate sand
User was not previously found, adding to dictionary.
dict_keys(['I hate sand'])
{'I hate sand': None}
The bounty quest allows you to hunt mobs for cash! Location: Castle, steward's room(to the right in the throne room) [PM 1 for specifics, PM 2 for TIPS, PM 3 for possible bounties]
Replying...
(454, 222)
Found a waiting message
Found an open message
1003 424
Player messaged 1
1
I hate sand
User was not previously found, adding to dictionary.
dict_keys(['I hate sand'])
{'I hate sand': None}
The bounty quest allows you to hunt mobs for cash! Location: Castle, steward's room(to the right in the throne room) [PM 1 for specifics, PM 2 for TIPS, PM 3 for possible bounties]
Replying...
キーが存在するかどうかを確認している場合は、 'playerでname_imageではない場合:'を使用します。 – Darkstarone
'name_image'は' players.keys() 'から取られます。どのような状況下では、値「None」にリンクされていますか? – khelwood
http://stackoverflow.com/help/someone-answers – e4c5