Page 2 of 2

Re: Save File Possible? Examples? :SOLVED:

Posted: Fri Jan 29, 2021 9:41 am
by Jdulay
Hi team.
Hey, guess what, it looks like we've done it!
I got save files working.

I used the code:

fatInitDefault();
Dim Content As String = "Save success success get!"
Write_File(Content, "saveTest.txt")

And it successfully created a new file with that string data.

I was able to successfully open the text file as well.
It looks like we needed that fatInitDefault(); in the beginning.

Good work, everyone. Now we can all have Save Data in our games. I'm still new to use DS Game Maker, so I'm not exactly sure how to take the string data and turn it into usable integer values for the game. I'm not sure how delimiter formating and parsing string to text works in DSGM, so any assistance in say, saving 10 different values, say for item quantity, and save it to text, then turn load it back into the game.
How do we use the values from a global variable as the Content?
Anway, hey, at least we got Saves working.

Well done, team.

Cheers
Jerrel

Re: Save File Possible? Examples?

Posted: Fri Jan 29, 2021 11:51 pm
by DigitalDesignDude
@Jdulay Glad you figured out how to successfully write text to a file. :)

Looks like finding a way to save and load variable values is the next challenge.

Wish I knew more myself on how that would be accomplished. Hoping that someone with more of a computer science background can share some insight.

Re: Save File Possible? Examples?

Posted: Sun Jan 31, 2021 6:39 am
by Jdulay
DigitalDesignDude wrote: Fri Jan 29, 2021 11:51 pm @Jdulay Glad you figured out how to successfully write text to a file. :)

Looks like finding a way to save and load variable values is the next challenge.

Wish I knew more myself on how that would be accomplished. Hoping that someone with more of a computer science background can share some insight.
I work in C# and Unity, and interpreting data from a saved line of text is quite easy. My approach for some situations is to use comma "," as a delimiter. I get Unity to read a number value from the file until it reaches a ",", and I can then say, "playerMoney = ..." so and so. And then I say, "playerEXP = ..." the next value that comes after that ",".

I assume we are working in C here with DSGM, which I have only minimal experience with. That makes it a real challenge on my side of things. I'm quite busy with work and don't have the time to learn the C necessary to accomplish the same task in C.

Can anyone else weigh in on this?

Re: Save File Possible? Examples?

Posted: Mon Feb 01, 2021 1:18 am
by DigitalDesignDude
Good news, it seems I found out how to get saving and loading to work with variables and have provided an example DSGM 5.12 project below. :)

I managed to figure it out by using the same save and load actions code from DSGM 4.9.


The only problem is, it looks like I can only load the save data when the .nds file is running on actual DS hardware (i.e using an r4 card).

When I use an emulator I can't locate the .sav file that's normally created after saving, and variable values are not saved after closing the emulator.

It's possible the .sav file has been created and it's just not where my emulator can find it.

Perhaps someone else can give my example .nds a try and see if it works with their emulator.


DSGM Save And Load Variables Example
https://digitaldesigndude.itch.io/ds-ga ... r-examples

Re: Save File Possible? Examples?

Posted: Mon Feb 01, 2021 1:21 am
by Ruffsta
James is currently away.. i can however pass the info/request to him.. i dunno when he'll reply..

Re: Save File Possible? Examples?

Posted: Mon Feb 01, 2021 3:34 am
by imadedsgamemaker
Glad you got something working. You will have to write some C to save specific variables, or use a file for each variable (?). If you're storing numbers you'll have to "cast" the loaded string back to a number. In C try the atoi function for that (just Googled it). I don't think type casting will work (e.g. int x = (int) char) because the char is a pointer not a value. My C is extremely rusty, fyi.

On using multiple variables in a single file, the delimiter approach is 100% the right way to, split with a comma. DSGM uses this method internally a LOT (eg inside the XDS files). It would be cool to bake this into an action - or if easier just the above part (loading a whole file into a integer variable, e.g. to save a high score or last achieved level). Who wants to try it? Check out the existing actions - should be enough inspiration between all of them.

Re: Save File Possible? Examples?

Posted: Sat Apr 03, 2021 5:01 pm
by DigitalDesignDude
I found some more information on saving and loading variables from looking at the DSGM 5.0 manual and searching the old DSGM forum with Wayback Machine.

From this excerpt in the DSGM 5 manual, it seems DSGM was never able to save and load without actual DS hardware.

Screenshot of DSGM 5 Manual Regarding Saving.png
Screenshot of DSGM 5 Manual Regarding Saving.png (109.1 KiB) Viewed 3690 times


It seems the reason for that is because:
emulation of the NDS doesn’t support the fat library.
as stated in this old tutorial for saving I found on the old forum.

Guide on How to Implement Game Saving by old Forum User
https://web.archive.org/web/20110624001 ... f=6&p=6969


I do not know if saving on emulators will work by using another library, but as a workaround, perhaps people can still use save states to play and save their progress for DSGM games?

I haven't been successful so far with my tests, but maybe someone more experienced with DS emulation may be able to get it to work.

At least should anyone want to make a physical DSGM game, we have an example solution that works on a real Nintendo DS.