ChrisNeedham24 / microcosm

A little 4X game written using Pyxel.
GNU General Public License v3.0
9 stars 8 forks source link

OSError when auto-saving on Windows #68

Closed jamesgiu closed 1 year ago

jamesgiu commented 1 year ago
Traceback (most recent call last):
  File "C:\Users\james\microcosm\game.py", line 255, in on_update
    if self.end_turn():
  File "C:\Users\james\microcosm\game.py", line 635, in end_turn
    self.save_game(auto=True)
  File "C:\Users\james\microcosm\game.py", line 824, in save_game
    with open(save_name, "w", encoding="utf-8") as save_file:
OSError: [Errno 22] Invalid argument: 'saves/autosave-2022-10-01T12:47:13.json'
PS C:\Users\james\microcosm> Traceback (most recent call last):                           File "C:\Users\james\microcosm\game.py", line 255, in on_update                                                         if self.end_turn():                                      File "C:\Users\james\microcosm\game.py", line 635, in end_turn                                                          self.save_game(auto=True)                                File "C:\Users\james\microcosm\game.py", line 824, in save_game                                                         with open(save_name, "w", encoding="utf-8") as save_file:                                                      
   OSError: [Errno 22] Invalid argument: 'saves/autosave-2022-10-01T12:47:13.json'
ChrisNeedham24 commented 1 year ago

The problem here is presumably that forward slashes are being used when Windows needs backslashes. The way to solve this would be to use os.path.join() with saves and then the save name.

jamesgiu commented 1 year ago

Thanks for confirming. Yeah it does sound like the classic slash. Hoping to look at this soon.

ChrisNeedham24 commented 1 year ago

This almost certainly extends to loading games as well.