Save System on nibble

Hi! I’m new to the nibble, I just finished building mine. I have an idea for a game, but it would need a save system. How could I accomplish this? Do variables stay the same if you don’t set them to a value at the start?

1 Like

I was wondering that too. I currently don’t know, but if I figure it out I’ll be sure to post it.

Nothing to it really guys. Use the eeprom lib and you can save and read values from the flash (emulated eeprom).

Check out my Sokoban game source for example of usage:

1 Like

Hey @sinkews, thanks for helping out!

Hi.
I was trying to save highscores, but no lubk.
I basically copied files from space rocks and no luck.

I tried to save some text and read and what i find out is that when i save and read it works. When i save, turn the device off and on again it doesn’t work.
I guess I’m missing out on something but don’t know what.
I could use some help! :smiley:

Here’s my code:

#include <FS.h>
#include <LittleFS.h>

void Highscore::save(){
	File file = LittleFS.open("/Highscore.txt", "w");
	if (!file)
		Serial.println("FileNotOpened");

	String s = "Banana";
	Serial.println(s);
	file.print(s);
	file.close();
	Serial.println("Save");
}
void Highscore::load(){
	File file = LittleFS.open("/Highscore.txt", "r");
	if (!file)
		Serial.println("FileNotFound");

	String s = "";
	char c[100];
	int i = 0;
	 while(file.available()){
		 c[i] = file.read();
		 i++;
		 Serial.println(c);
	  }   

	file.close();
	s = String(c);
	Serial.println(s);
	Serial.println("Load");
}

Thank you!

1 Like

Hey @Crni03,

thank you for reaching out.

We forwarded this to our lead programmer, and he’ll take a look and help you out!

Sincerely,
Monika from CircuitMess

Hi, would be nice if someone could help with this. :slight_smile:

1 Like

Hey @Crni03,

so sorry you’re still waiting for the solution.

Unfortunately, our software team is very busy developing Batmobile right now.

We’ll contact you back in a few weeks when they catch some time to check this out.

In the meantime, it would be best if you tried to find the solution on your own or from the other members of Community or Discord.

Thank you for your patience,
Monika

1 Like

As I said already use the EEPROM lib available in Arduino.

#include <EEPROM.h>

byte data = 0;

In your setup routine put this:
EEPROM.begin(512);

To save:
EEPROM.write(0, data);
EEPROM.commit();

To load:
data = EEPROM.read(0);

Nothing to it really :stuck_out_tongue_winking_eye:

512 is the size of emulated EEPROM.
I put address 0 but you are free to use any address in the range from 0 to 512 (or larger or smaller, depends how many space you need)

1 Like

Thank you! I used Put and Get functions and it worked like a charm! :slight_smile:

void HighscoreImpl::save()
{
	EEPROM.put(0, data);
	EEPROM.commit();	
}
void HighscoreImpl::load(){
	EEPROM.get(0, data);	
}

Data is s struct.
I put this code here in case someone should need it. :slight_smile:

2 Likes