Highscores and Savegames, how do I do it?

Understanding the language, error messages, etc.

Highscores and Savegames, how do I do it?

Postby JWinslow23 » Sun Mar 01, 2015 6:31 pm

Hey, guys. I'm new to the Gamebuino community, and I wanna know about how to make a savegame or a highscore (or a list of highscores, but maybe later). How would I do it? I poked around on the forums, and it looks like something called EEPROM has something to do with it?
User avatar
JWinslow23
 
Posts: 36
Joined: Sun Feb 22, 2015 8:16 pm

Re: Highscores and Savegames, how do I do it?

Postby Myndale » Mon Mar 02, 2015 7:34 am

Yes, Gamebuino uses the ATMega328p micro-controller which has 1024 bytes of EEPROM. The easiest way to access it is via the built-in EEPROM library which is documented here:

http://arduino.cc/en/Reference/EEPROM

In my BuinoWars project there is a file called saveload.ino which shows how to save and load an entire structure, including validity checks to see if a previous savegame (or high score table) is already present.
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Highscores and Savegames, how do I do it?

Postby JWinslow23 » Tue Mar 03, 2015 5:46 pm

And is it possible to be able to quit the game and still be able to load the save next time you load the game? I'm trying in Simbuino, and when I press C on the title screen, it erases the saved game.
User avatar
JWinslow23
 
Posts: 36
Joined: Sun Feb 22, 2015 8:16 pm

Re: Highscores and Savegames, how do I do it?

Postby Myndale » Tue Mar 03, 2015 9:41 pm

JWinslow23 wrote:And is it possible to be able to quit the game and still be able to load the save next time you load the game? I'm trying in Simbuino, and when I press C on the title screen, it erases the saved game.


That shouldn't be happening. EEPROM persists until it's overridden by another app or cleared by the menu, it also saves itself to settings between Simbuino sessions. Which game are you running?
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Highscores and Savegames, how do I do it?

Postby JWinslow23 » Wed Mar 04, 2015 12:42 am

For my 2048 game (and some other games like Paqman, Asterocks, haven't tested others) whenever I press C on the title screen, the highscores erase. Download the .zip here.

I want the savegame and highscore to persist until I play the game again.

Also, something weird happened when I played Crabator after 2048...
Image
Just so you know, I store my savegame as:
A string that says "2048 GAMEBUINO"
An array with all the board values (at the time, it was [5 3 0 0 2 0 0 0 1 0 0 0 0 2 0 0])
Current score (144 at the time)
Highest score (144 at the time)

This at least tells me I'm storing it right...and that they're persisting in memory...but that pressing C at the title screen issue is kinda bugging me a bit (no pun intended).

I've also heard of people making .sav files?
User avatar
JWinslow23
 
Posts: 36
Joined: Sun Feb 22, 2015 8:16 pm

Re: Highscores and Savegames, how do I do it?

Postby Myndale » Wed Mar 04, 2015 2:01 am

JWinslow23 wrote:For my 2048 game (and some other games like Paqman, Asterocks, haven't tested others) whenever I press C on the title screen, the highscores erase.


Are you sure you're running the latest version of Simbuino? There were some problems with the EEPROM display a little while ago which were subsequently fixed.

JWinslow23 wrote:I want the savegame and highscore to persist until I play the game again.


When I compile and run your code I see it updating EEPROM correctly but pressing C from the title screen doesn't do anything. However, now that I've looked into it I've discovered that although EEPROM persists across "Load Game" it isn't being saved to the settings file correctly, so if you quit Simbuino and run it again the EEPROM gets erased. (Thanks for bringing it to my attention!) There's a major release coming out next week which now has this fix along with a few others (support for EEPROM Load/Save, displaying the version number etc), I'll be announcing it on the Simbuino forum thread when it's available so you may want to hang on until then.

JWinslow23 wrote:Also, something weird happened when I played Crabator after 2048...

JWinslow23 wrote:I've also heard of people making .sav files?


Looks like Crabator doesn't check EEPROM to make sure there's a valid game there. Simbuino hasn't been designed to replace Gamebuino, it's just a tool to help with development. When you change games on the real hardware it saves and restores the EEPROM for the games in the .SAV files.

Great game btw, it's a genre I enjoy when I have a few spare moments on the train and I had fun playing it :) The one suggestion I would make though is to give the player the option of when to save the game instead of doing it every turn. EEPROM is only guaranteed for 100k write cycles, if every game wrote to EEPROM a few hundred times a session (which yours easily could wind up doing) and people played 5 games per day (say) then the EEPROM could be permanently destroyed in just a couple of months. In reality most games don't do this and EEPROM typically outlasts it's spec'd write cycles by an order of magnitude, but as developers we should err on the side of caution and only write to it when we absolutely need to.
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Highscores and Savegames, how do I do it?

Postby JWinslow23 » Wed Mar 04, 2015 4:48 pm

Myndale wrote:
JWinslow23 wrote:For my 2048 game (and some other games like Paqman, Asterocks, haven't tested others) whenever I press C on the title screen, the highscores erase.


Are you sure you're running the latest version of Simbuino? There were some problems with the EEPROM display a little while ago which were subsequently fixed.

JWinslow23 wrote:I want the savegame and highscore to persist until I play the game again.


When I compile and run your code I see it updating EEPROM correctly but pressing C from the title screen doesn't do anything. However, now that I've looked into it I've discovered that although EEPROM persists across "Load Game" it isn't being saved to the settings file correctly, so if you quit Simbuino and run it again the EEPROM gets erased. (Thanks for bringing it to my attention!) There's a major release coming out next week which now has this fix along with a few others (support for EEPROM Load/Save, displaying the version number etc), I'll be announcing it on the Simbuino forum thread when it's available so you may want to hang on until then.

JWinslow23 wrote:Also, something weird happened when I played Crabator after 2048...

JWinslow23 wrote:I've also heard of people making .sav files?


Looks like Crabator doesn't check EEPROM to make sure there's a valid game there. Simbuino hasn't been designed to replace Gamebuino, it's just a tool to help with development. When you change games on the real hardware it saves and restores the EEPROM for the games in the .SAV files.

Great game btw, it's a genre I enjoy when I have a few spare moments on the train and I had fun playing it :) The one suggestion I would make though is to give the player the option of when to save the game instead of doing it every turn. EEPROM is only guaranteed for 100k write cycles, if every game wrote to EEPROM a few hundred times a session (which yours easily could wind up doing) and people played 5 games per day (say) then the EEPROM could be permanently destroyed in just a couple of months. In reality most games don't do this and EEPROM typically outlasts it's spec'd write cycles by an order of magnitude, but as developers we should err on the side of caution and only write to it when we absolutely need to.


I believe I'm running the latest version...but I'll update soon to be sure. I also hope to make an agreement with my parents to buy me a real one of these.

And nice to know. I'll simply make it save when the player exits to the title screen. How's that sound?
User avatar
JWinslow23
 
Posts: 36
Joined: Sun Feb 22, 2015 8:16 pm


Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 5 guests

cron