Page 1 of 1

saving data to the SD card

PostPosted: Sat Oct 08, 2016 5:28 pm
by noah
Hi,
How would I save data to the SD card, I want to save a score variable to be shown in the next game... I looked through some of the examples but didn't really understand what was going on. What is the easiest way?

Thanks in advance, Noah :)

Re: saving data to the SD card

PostPosted: Mon Oct 10, 2016 5:19 am
by Sorunome
For simple highscore storage stuff you use the EEPROM, the loader automatically handles saving that to sd card and loading from it :)

Re: saving data to the SD card

PostPosted: Mon Oct 10, 2016 5:58 am
by noah
How do you write to eeprom? It doesn't appear to have anything about it in the reference.

Re: saving data to the SD card

PostPosted: Mon Oct 10, 2016 9:09 am
by rodot
That's because the EEPROM library is part of Arduino, not Gamebuino ;)
See the Arduino EEPROM library reference.

Re: saving data to the SD card

PostPosted: Tue Oct 11, 2016 6:29 am
by wuuff
I think it would be really helpful if the reference had a brief discussion of the way that the loader deals with the eeprom, because I had to look through the source of the loader to be sure I understood how it worked.

If I recall, the loader automatically saves the eeprom of a program whenever it starts if any byte in the eeprom is not zero, and the eeprom contents are saved in a .SAV file on the SD card with the same name as the game. Otherwise, it will not bother to save it. Then, right before flashing a game, it checks whether a save file exists for that game and, if so, populates the eeprom with the contents of that save file. I wanted to check this when I was adding highscores to a game because it was not clear to me at first whether I needed to do anything special besides just writing to eeprom.

Is it welcomed here for anyone to make additions to the wiki? I think it would be helpful to have a simple explanation about this, and I would be happy to do it myself if nobody objects to the idea. I just don't want to upset anyone if somebody objects and thinks it isn't needed.

Re: saving data to the SD card

PostPosted: Tue Oct 11, 2016 7:04 am
by Sorunome
What you just said about the eeeprom is correct, it would be great if you could add it to the wiki for others! :D