switchbrew / switch-examples

Switch examples for devkitA64 and libnx.
https://devkitpro.org/viewforum.php?f=42
559 stars 99 forks source link

Creating a save example #94

Closed EimaMei closed 2 years ago

EimaMei commented 2 years ago

I wasn't able to find information on how to create a savefile for a homebrew game. If it isn't possible, then is there any other way to save information as a file?

fincs commented 2 years ago

Homebrew apps run by replacing an existing official app's executable, but they retain their context. As such, trying to use the native savegame APIs would result in homebrew carelessly overwriting and corrupting people's savegames for the target titles they choose to use for running homebrew.

The recommended way to handle homebrew saves is by simply creating files on the SD card with the standard C file routines (stdio). Please note that the default working directory is the same as the directory that holds the NRO; it is strongly recommended to use this directory for any saved data produced by homebrew applications. This means you can just do something like fopen("mygame.cfg", "w") for write access.

EimaMei commented 2 years ago

Oh okay! Makes sense now, thank you for the help