Understanding the language, error messages, etc.
by naed » Sat Nov 12, 2016 11:23 pm
I wonder if anyone could help me with the simplest way to save my byte values to EEPROM??
is it as simple as this?
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
#include <EEPROM.h>
Gamebuino gb;
byte number1 = 1;
byte number2 = 2;
EEPROM.write(0, number1);
and then to read them
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
#include <EEPROM.h>
Gamebuino gb;
byte number1;
number1 = EEPROM.read(0)
to be honest I've looked at the examples in all the games that use saves but am struggling to understand how to save to EEPROM - the above is the simplest way I've seen it explained but not sure if it will work at all?
-
naed
-
- Posts: 140
- Joined: Tue May 31, 2016 3:18 pm
by Sorunome » Sun Nov 13, 2016 11:45 am
Yeah, that is exactly how you do it.
When you start your game for the first time and haven't modified eeeprom yet everything is zero, so when you are saving something it might be a good idea to just write a 1 at place 0 so that you know there is actually a save.
You don't have to worry about other games changing eeeprom and stuff, the loader takes care of that while switching games.
EDIT: Of cource that exact sample wouldn't work as the code you run needs to be either in the setup() or the loop() function, outside of functions you can only variable definitions, such as byte number1 = 1;
-
Sorunome
-
- Posts: 629
- Joined: Sun Mar 01, 2015 1:58 pm
-
by naed » Sun Nov 13, 2016 7:49 pm
Thanks Sorunome
Yeah I'm aware that exact example wouldn't work but that was only written to give an example of what I'm trying to achieve...
you may know the answer to this question also...
If I load another game whilst in my own game using the load_game(MYGAME) function, is it true that EEPROM will not be reset, thus allowing me to carry over a save files to another game??
-
naed
-
- Posts: 140
- Joined: Tue May 31, 2016 3:18 pm
by Sorunome » Sun Nov 13, 2016 10:06 pm
yes, that is true. load_game only flashes the game, it does nothing at all with eeeprom.
load_game("LOADER") would flash the loader, the loader itself detects that it has been, well, loaded, takes the eeeprom and saves it to the SD card. Then when the user picks a game it checks if there is a savefile on the SD card, if there is one it'll write that one to eeeprom manually before calling load_game
-
Sorunome
-
- Posts: 629
- Joined: Sun Mar 01, 2015 1:58 pm
-
by naed » Sun Nov 13, 2016 10:16 pm
Awesome, and thanks again for the response
Looks like I'm setting myself up for a long night of working on my game
-
naed
-
- Posts: 140
- Joined: Tue May 31, 2016 3:18 pm
by naed » Fri Nov 25, 2016 10:26 pm
Just an update to this... I managed to get this to work and you can view the results in my main project thread if you'd like to
viewtopic.php?f=13&t=3509
-
naed
-
- Posts: 140
- Joined: Tue May 31, 2016 3:18 pm
Return to Programming Questions
Who is online
Users browsing this forum: No registered users and 3 guests