Homebrew Save hiscore

Cid2mizard

Well-Known Member
OP
Member
Joined
Aug 16, 2007
Messages
401
Trophies
1
Age
43
Location
Maubeuge
XP
2,449
Country
France
Hello,

I wish I save the scores in a file on the SD card , as simply as possible ... the save file is created but it does 1ko and contains nothing ...

Code:
//A sauvergarder
bool niveau_unlocked[MAX_LVL];
bool niveau_solved[MAX_LVL];
u8 niveau_best[MAX_LVL];
//End save
 
void sauvegarder()
{
    fsInit();
 
    u32 bytesWrite;
    Handle fileHandle;
 
    char filename[15] = "/TILES_2DS.SAV";
 
    //setup SDMC archive
    FS_archive sdmcArchive = (FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
 
    //create file path struct
    FS_path filePath = FS_makePath(PATH_CHAR, filename);
 
    //create file
    FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ|FS_OPEN_WRITE|FS_OPEN_CREATE, FS_ATTRIBUTE_NONE);
 
    //Write file
    for (i = 0; i < MAX_LVL; i++)
    {
        FSFILE_Write(fileHandle, &bytesWrite, 0x0, &niveau_unlocked[i], sizeof(niveau_unlocked[i]), FS_WRITE_FLUSH);
        FSFILE_Write(fileHandle, &bytesWrite, 0x0, &niveau_solved[i], sizeof(niveau_solved[i]), FS_WRITE_FLUSH);
        FSFILE_Write(fileHandle, &bytesWrite, 0x0, &niveau_best[i], sizeof(niveau_best[i]), FS_WRITE_FLUSH);
    }
 
    //Close file
    FSFILE_Close(fileHandle);
    svcCloseHandle(fileHandle);
}
 

Technicmaster0

Well-Known Member
Member
Joined
Oct 22, 2011
Messages
4,410
Trophies
2
Website
www.flashkarten.tk
XP
3,513
Country
Gambia, The
Hello,

I wish I save the scores in a file on the SD card , as simply as possible ... the save file is created but it does 1ko and contains nothing ...

Code:
//A sauvergarder
bool niveau_unlocked[MAX_LVL];
bool niveau_solved[MAX_LVL];
u8 niveau_best[MAX_LVL];
//End save
 
void sauvegarder()
{
    fsInit();
 
    u32 bytesWrite;
    Handle fileHandle;
 
    char filename[15] = "/TILES_2DS.SAV";
 
    //setup SDMC archive
    FS_archive sdmcArchive = (FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
 
    //create file path struct
    FS_path filePath = FS_makePath(PATH_CHAR, filename);
 
    //create file
    FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ|FS_OPEN_WRITE|FS_OPEN_CREATE, FS_ATTRIBUTE_NONE);
 
    //Write file
    for (i = 0; i < MAX_LVL; i++)
    {
        FSFILE_Write(fileHandle, &bytesWrite, 0x0, &niveau_unlocked[i], sizeof(niveau_unlocked[i]), FS_WRITE_FLUSH);
        FSFILE_Write(fileHandle, &bytesWrite, 0x0, &niveau_solved[i], sizeof(niveau_solved[i]), FS_WRITE_FLUSH);
        FSFILE_Write(fileHandle, &bytesWrite, 0x0, &niveau_best[i], sizeof(niveau_best[i]), FS_WRITE_FLUSH);
    }
 
    //Close file
    FSFILE_Close(fileHandle);
    svcCloseHandle(fileHandle);
}
You can look at the source of my Guess the Number. The only well-written part are the "files.h" and "files.c" files which contain exactly the methods you need. I think that you can write simply serveral saves by using one archive that contains serveral text files containing the scores.
 
  • Like
Reactions: Cid2mizard

Cid2mizard

Well-Known Member
OP
Member
Joined
Aug 16, 2007
Messages
401
Trophies
1
Age
43
Location
Maubeuge
XP
2,449
Country
France
Ok thank you both , it works now ...

Code:
void sauvegarder()
{
    char filename[15] = "/TILES_2DS.sav";
 
    FILE *file = fopen(filename,"w+b");
 
    //Write file
    for (i = 0; i < MAX_LVL; i++)
    {
        fwrite(&niveau_unlocked[i], sizeof(niveau_unlocked[i]), 1, file);
        fwrite(&niveau_solved[i], sizeof(niveau_solved[i]), 1, file);
        fwrite(&niveau_best[i], sizeof(niveau_best[i]), 1, file);
    }
 
    //Close file
    fclose(file);
}
 
 
void charger()
{
    char filename[15] = "/TILES_2DS.sav";
    u8 erreur = 0;
 
    FILE* file = fopen(filename, "r+b");
 
    if (file != 0)
    {
        for (i = 0; i < MAX_LVL; i++)
        {
            fread(&niveau_unlocked[i], 1, sizeof(niveau_unlocked[i]), file);
            fread(&niveau_solved[i], 1, sizeof(niveau_solved[i]), file);
            fread(&niveau_best[i], 1, sizeof(niveau_best[i]), file);
        }
        fclose(file);
    }
    else
    {
        erreur = 1;
    }
 
    if (erreur == 1)
    {
        sauvegarder();
    }
}
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • Veho @ Veho:
    That's a relief to hear. Do you know what happened?
  • SylverReZ @ SylverReZ:
    @BakerMan, Any idea what happened? I hope that your brother's doing good.
  • BakerMan @ BakerMan:
    Well, from what I've heard from my parents, he had a seizure last night, perhaps an epileptic episode, fucking died, had a near death experience, my dad called the paramedics, they showed up, took him to the hospital, and he woke up covered in tubes, and started complaining.
  • BakerMan @ BakerMan:
    He couldn't eat until after his MRI, when he had a bomb pop.
  • BakerMan @ BakerMan:
    What matters now is that he's doing alright.
  • Veho @ Veho:
    But you still don't know what it was?
  • Veho @ Veho:
    Has he had seizures before?
  • The Real Jdbye @ The Real Jdbye:
    apparently stress can cause seizures, my brother had one during a test once
  • The Real Jdbye @ The Real Jdbye:
    never had one before that, and never had one since
  • Redleviboy123 @ Redleviboy123:
    Question about game texture chanching Do i need an own game id?
  • The Real Jdbye @ The Real Jdbye:
    @Veho for those that want to
    experience being sonic the hedgehog
  • Veho @ Veho:
    Ah, you mean
    furries.
    +1
  • The Real Jdbye @ The Real Jdbye:
    well, sonic fans are a whole separate thing from furries
  • The Real Jdbye @ The Real Jdbye:
    like bronys
  • The Real Jdbye @ The Real Jdbye:
    sonic porn is too weird even for me
  • Dumpflam @ Dumpflam:
    bruh
  • Dumpflam @ Dumpflam:
    guys how do i delete a post
  • The Real Jdbye @ The Real Jdbye:
    you don't
  • The Real Jdbye @ The Real Jdbye:
    you can report it and request deletion
  • BakerMan @ BakerMan:
    Also, no, that was his first time having a seizure, and hopefully the last
    +1
  • K3Nv2 @ K3Nv2:
    Ea play raised priced to $6 a month lol
  • BigOnYa @ BigOnYa:
    Same with uremum, she's now $2 a month
  • K3Nv2 @ K3Nv2:
    Also seizures come and and go they don't have an off switch like that it all depends
    K3Nv2 @ K3Nv2: Also seizures come and and go they don't have an off switch like that it all depends