Your main issue here is that for each of the score saves, you do the following:
- Open the file
- Write the data
- Close the file
With the above, the file's ModeFlag
(that second arg on the open
call), is really important.
You're using File.WRITE_READ
) which is documented as:
Opens the file for read and write operations. The file is created if it does not exist, and truncated if it does. The cursor is positioned at the beginning of the file.
So, that means, even if the file exist, it'll be emptied on open. So, if you saved something in it the first time, when you open it for the second save, you're effectively wiping out the contents you just put in it.
It'd be easier to change your save and load code to save and load everything all at once if possible.
So...
- Open the file
- Save (or load) everything
- Close the file
That way, the "truncation" doesn't matter. If you really do need to "open | write | close" for each item, then you'll have to get fancier.
Specifically, you'll want to change your ModeFlag
to READ_WRITE
, which is documented to NOT truncate the existing file. But, even then, the open will leave the cursor at the beginning of the file. To "append" data, you'll need to manually move the cursor to the end - likely via File.seek_end()
.