実現したいこと
pygameでポケモンの対戦を再現しようとしています。現段階でメッセージを表示する仕組みを作ろうとGeminiも使って作成していたらエラーが発生しました。
発生している問題・分からないこと
実行して努力値等必要なところを選択して実際に対戦する画面になり,技を選択するとエラーが発生します。見た感じエラーが2つ発生しています。
エラーメッセージ
error
1File "f:\python用\pokemon_update.py", line 576, in <module> 2 main.main() 3 File "f:\python用\pokemon_update.py", line 571, in main 4 self.page_6() 5 File "f:\python用\pokemon_update.py", line 514, in page_6 6 multiprocessing.Process(target=self.atk.attack, args=(self.player, self.attack_kind(), self.select[self.player], 1)).start() 7 File "C:\Users\s02\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\process.py", line 121, in start 8 self._popen = self._Popen(self) 9 ^^^^^^^^^^^^^^^^^ 10 File "C:\Users\s02\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\context.py", line 224, in _Popen 11 return _default_context.get_context().Process._Popen(process_obj) 12 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13 File "C:\Users\s02\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\context.py", line 336, in _Popen 14 return Popen(process_obj) 15 ^^^^^^^^^^^^^^^^^^ 16 File "C:\Users\s02\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\popen_spawn_win32.py", line 94, in __init__ 17 reduction.dump(process_obj, to_child) 18 File "C:\Users\s02\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\reduction.py", line 60, in dump 19 ForkingPickler(file, protocol).dump(obj) 20TypeError: cannot pickle 'pygame.surface.Surface' object 21PS F:\python用> Traceback (most recent call last): 22 File "<string>", line 1, in <module> 23 File "C:\Users\s02\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\spawn.py", line 120, in spawn_main 24 exitcode = _main(fd, parent_sentinel) 25 ^^^^^^^^^^^^^^^^^^^^^^^^^^ 26 File "C:\Users\s02\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\spawn.py", line 130, in _main 27 self = reduction.pickle.load(from_parent) 28 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 29EOFError: Ran out of input
該当のソースコード
pokemon_update.py
1import random 2from pokemon_class1 import speed_order, Attack, Actual_value 3from pokemon_class2_excel import Excel 4import pygame, sys 5from pygame.locals import * 6from tkinter import messagebox 7import time 8import multiprocessing 9import queue 10 11class Main(): 12 def __init__(self): 13 #省略 14 pass 15 16 def value_calculation(self): 17 self.character_list = ["さみしがり", "いじっぱり", "やんちゃ", "ゆうかん", "ずぶとい", "わんぱく", "のうてんき ", "のんき", 18 "ひかえめ", "おっとり", "うっかりや", "れいせい", "おだやか", "おとなしい", "しんちょう", "なまいき", 19 "おくびょう", "せっかち", "ようき", "むじゃき", "がんばりや ", "すなお", "てれや", "きまぐれ", "まじめ"] 20 self.big_list[0]["character"] = random.choice(self.character_list) 21 self.big_list[1]["character"] = random.choice(self.character_list) 22 self.big_list[0]["individual"] = [] 23 self.big_list[1]["individual"] = [] 24 for i in range(6): 25 self.big_list[0]["individual"].append(random.randint(0,31)) 26 self.big_list[1]["individual"].append(random.randint(0,31)) 27 28 self.big_list[0]["acv"] = Actual_value(self.big_list[0]["value"], self.big_list[0]["individual"], self.big_list[0]["effort_level"], self.big_list[0]["character"], self.big_list[0]["type"], self.big_list[2]["place"]["weather"], self.big_list[2]["place"]["wonder_room"]) 29 self.big_list[0]["actual_value"] = self.big_list[0]["acv"].value_return() 30 self.big_list[1]["acv"] = Actual_value(self.big_list[1]["value"], self.big_list[1]["individual"], self.big_list[1]["effort_level"], self.big_list[1]["character"], self.big_list[1]["type"], self.big_list[2]["place"]["weather"], self.big_list[2]["place"]["wonder_room"]) 31 self.big_list[1]["actual_value"] = self.big_list[1]["acv"].value_return() 32 33 #HP 34 self.big_list[0]["max_HP"] = self.big_list[0]["actual_value"][0] 35 self.big_list[1]["max_HP"] = self.big_list[1]["actual_value"][0] 36 self.big_list[0]["now_HP"] = self.big_list[0]["max_HP"] 37 self.big_list[1]["now_HP"] = self.big_list[1]["max_HP"] 38 39 def value_calculation_second(self): 40 self.big_list[0]["acv"] = Actual_value(self.big_list[0]["value"], self.big_list[0]["individual"], self.big_list[0]["effort_level"], self.big_list[0]["character"], self.big_list[0]["type"], self.big_list[2]["place"]["weather"], self.big_list[2]["place"]["wonder_room"]) 41 self.big_list[0]["actual_value"] = self.big_list[0]["acv"].value_return() 42 self.big_list[1]["acv"] = Actual_value(self.big_list[1]["value"], self.big_list[1]["individual"], self.big_list[1]["effort_level"], self.big_list[1]["character"], self.big_list[1]["type"], self.big_list[2]["place"]["weather"], self.big_list[2]["place"]["wonder_room"]) 43 self.big_list[1]["actual_value"] = self.big_list[1]["acv"].value_return() 44 45 #self.big_listの要素はまだある 46 47 def page_6(self): #ゲーム画面 48 self.background = pygame.image.load("ポケモン/背景.png") 49 self.floor = pygame.image.load("ポケモン/床.png") 50 self.me = pygame.image.load("ポケモン/michimo_back.png") 51 self.cpu = pygame.image.load("ポケモン/michimo_front.png") 52 53 self.execution_int = 0 54 55 self.screen_bilt() 56 57 self.display_HP() 58 self.display_attack() 59 60 if not self.execution: 61 for i in range(4): 62 if self.big_list[0]["PP"][i] > 0: 63 self.display_list["attack"][i] = True 64 65 self.message_log = "技を選択してください" 66 67 # イベント処理 68 for event in pygame.event.get(): 69 if event.type == QUIT: 70 pygame.quit() 71 sys.exit() 72 if event.type == pygame.MOUSEBUTTONDOWN: 73 for i in range(4): 74 if pygame.Rect(800, 410 + i * 70, 250, 60).collidepoint(event.pos): 75 self.display_list["attack"] = [False, False, False, False] 76 self.execution_int = 1 77 self.screen_bilt() 78 self.display_HP() 79 self.display_attack() 80 pygame.display.flip() 81 self.my_select = i 82 self.atk = Attack(self.big_list, self.message_get) 83 self.cpu_select = random.randint(0, 3) #変更する可能性あり 84 self.select = [self.my_select, self.cpu_select] 85 self.speed = speed_order(self.big_list[0]["actual_value"][5], self.big_list[0]["ability_change"][5], self.big_list[0]["situation"], 86 self.big_list[1]["actual_value"][5], self.big_list[1]["ability_change"][5], self.big_list[1]["situation"], 87 self.ex.excel1(self.big_list[0]["attack"][self.my_select])[11], self.ex.excel1(self.big_list[1]["attack"][self.cpu_select])[11], self.big_list[2]["place"]["wonder_room"]) 88 self.player = self.speed 89 multiprocessing.Process(target=self.atk.attack, args=(self.player, self.attack_kind(), self.select[self.player], 1)).start() 90 multiprocessing.Process(target=self.return_variable).start() 91 self.player = 0 if self.speed == 1 else 1 92 if self.big_list[self.player]["now_HP"] > 0: #攻撃時にHPがあるときのみ攻撃 93 self.atk.init_second(self.big_list) 94 multiprocessing.Process(target=self.atk.attack, args=(self.player, self.attack_kind(), self.select[self.player], 2)).start() 95 multiprocessing.Process(target=self.return_variable).start() 96 multiprocessing.Process(target=self.atk.turn_end).start() 97 multiprocessing.Process(target=self.return_variable).start() 98 del self.atk 99 100 try: 101 self.new_message = self.message_queue.get(False) 102 self.message_list.append((self.new_message)) 103 except queue.Empty: 104 pass 105 106 if self.message_log: 107 if time.time() - self.display_start_time >= 1: 108 self.message_log = None 109 self.display_start_time = 0 110 else: 111 self.message() 112 elif self.message_list: 113 self.message_log = self.message_list.pop(0) 114 self.display_start_time = time.time() 115 pygame.display.flip() 116 if self.message_log != "技を選択してください": 117 time.sleep(1) 118 time.sleep(0.05) 119 120 121 def main(self): 122 while True: 123 self.page_6() 124 125 126if __name__ == "__main__": 127 main = Main() 128 main.main()
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
googleで調べてみましたがあまりよくわかりませんでした。できればエラーの意味も教えてほしいです。個人的にはself.big_listが怪しいと睨んでいます。
結構省略してしまったのでわからないところがあれば質問してきてください。
補足
特になし
ソースコードの pokemon_update.py ですが、トレースバックを見ると、576行ある様です。肝心の部分(multiprocessing.Process()を呼び出している部分)が抜けているのと、インポートしている pokemon_class1.py と pokemon_class2.py が掲示されていませんので、当該のエラーの原因を調査することは困難かと思います。
File "f:\python用\pokemon_update.py", line 576, in <module>
main.main()
File "f:\python用\pokemon_update.py", line 571, in main
self.page_6()
File "f:\python用\pokemon_update.py", line 514, in page_6
multiprocessing.Process(target=self.atk.attack, args=(self.player, self.attack_kind(), self.select[self.player], 1)).start()

回答2件
あなたの回答
tips
プレビュー