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

Discussion in 'Programming' started by hughrock_projects, Sep 13, 2019.

  1. hughrock_projects

    hughrock_projects Member

    Joined:
    Jun 29, 2019
    Posts:
    4
    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!
     
  2. marasovec

    marasovec Member

    Joined:
    Sep 15, 2016
    Posts:
    319
    It's hard to tell without seeing the code ;)
    Maybe we can resolve the undefined value problem
     
  3. hughrock_projects

    hughrock_projects Member

    Joined:
    Jun 29, 2019
    Posts:
    4
    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.
     
  4. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    430
    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.
     
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,800
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice