GMS 2 What am I doing wrong with my data saving/loading?

H

hughrock_projects

Guest
Hello fellow indie devs!

This problem has had me stumped forever now (feels like it anyway).

I've looked up several "how-to" vids on saving and loading data in gms2. I've dabbled in using json-ds_map, ds_grid_read/write, and even ini files (hate them).

For some reason, that has me truly baffled, I can "save" data with all 3 of these methods. However, I can't seem to close my project and reload it. I always get the "undefined value" error. When debugging, I checked the various keys indexes I assigned to the ds_map. They all came back as <undefined> after attempting to load them.

I fear it would be far too tedious to explain what I'm aiming for (beyond saving/loading), and, as a result, I won't bother trying to copy and paste ALL the code needed to show what i'm doing. The project I'm working on is, honestly, irrelevant in the grand scheme of things. I need this answer for ALL projects i'm currently (and will be) working on.

What I'm looking for is what other's consider to be the "best" saving/loading method, and the "best" way to implement it. Obviously, I'm doing something wrong. These functions wouldn't have survived the transition from gms1.4 to gms2 if they didn't do what they were made to do. I've just never made it to the point of needing one until now.

I really appreciate any assist!
 
H

hughrock_projects

Guest
It's hard to tell without seeing the code ;)
Maybe we can resolve the undefined value problem
I appreciate it, but to be completely honest, I wouldn't know where to start and where to end. I was hoping to get an idea of how others use any of these methods.

Perhaps I could get a decent example? I really like the freedom the json method is supposed to offer, but I really like the simplicity in using secure_save/load.

You'll have to forgive me. I'm still pretty new to programming.
 

Alexx

Member
Depends what you need to save.
Just a highscore?
Location and values of all instances?
A data structure of some type?
More info is needed to suggest something relevant to your needs.
 

TheouAegis

Member
Best method in my opinion is writing everything to a buffer, encrypting the buffer, then saving the result. lo lAlthough the ds_map scure save might be easier to work with.

Make sure the location you are saving to isn't write-protected.

If you are doing a method that requires opening a file to write to it, make sure you close the file after writing. If you don't close it, it doesn't save.
 

TibiSoft

Member
If you are doing a method that requires opening a file to write to it, make sure you close the file after writing. If you don't close it, it doesn't save.
Thanks... I made a copy-paste error and skipped the ni_close line, and it resulted random save of the file. Closing ini solved the problem, of course.
 
Top