【发布时间】:2014-06-25 03:59:51
【问题描述】:
我尝试使用 JSON 文件和 Kivy 中的 json 存储语言为应用设置高分跟踪器。
我导入了 JSONstore,并在我的主游戏类中导入了
class Game(FloatLayout):
highscorejson = JsonStore('highscore.json')
highscore = NumericProperty(highscorejson.get('highscore')['best'])
在我初始化课程之后,我有一个结束游戏的函数,它结束游戏并检查新分数是否超过旧的高分。
def end_game(self):
if self.score > self.highscore:
self.highscorejson.put('highscore', best = self.score)
self.highscore = self.highscorejson.get('highscore')['best']
当我通过 Kivy 运行它时,它运行得很好,但是当我使用我的 iphone 作为测试设备通过 XCode 运行它时,当你得分高于高分并且游戏结束时它会崩溃。错误信息如下。
File "/usr/local/lib/python2.7/site-packages/kivy/storage/__init__.py", line 174, in put
File "/usr/local/lib/python2.7/site-packages/kivy/storage/jsonstore.py", line 39, in store_sync
IOError: [Errno 1] Operation not permitted: 'highscore.json'
2014-06-24 21:59:34.385 cookie[2320:60b] Application quit abnormally!
2014-06-24 21:59:34.457 cookie[2320:60b] Leaving
【问题讨论】: