top of page
Search

Using JSONObjects to store game data.

Hello developers! For the past couple days, I worked on creating save states and data using JSONObjects as my primary save method.


A JSONObject is essentially a bucket of variables, that can store multiple types of information. This includes floats, doubles, strings, ints, and more.


Unfortunately, a JSONObject cannot store a class object besides arrays and JSONObjects. Because of this, all data for classes/objects needs to be "encoded" inside of the JSONObject itself.


Processing has a pretty nice method for loading and saving JSONObjects, so I don't have to worry about that. The real question is assembly and usage. In order to do that, I have to check if the JSONObject exists in the first place. To do that, I assign the name of the JSONObject file a specific ID/name to find it. I create a new file object and check if that file object exists. I have to do it like that, as JSONObjects cannot be undefined. I tried many different ways, but that was the only way that worked.


I check if the JSONObject file exists and then load it. On loading it, I pull out all related JSONObjects. I have them organized into a specific tree path, which organizes the data based on where it will be used. This includes space data, walking data, and general player data.


After I pull the data out, I set the current data to the data I just retrieved. This essentially loads all the data needed, and everything is bueno! Right? Wrong. Because of all the data being completely unprotected, is very easy for tech savy users to just edit the data values inside. Because of this, we need a custom way to check if the data has been tampered with. To do this, we will copy our friend the bar code, which includes it's own self check at the end of the black and white lines. We do a mathematical formula on our data and at the end we add an ID to check if the data is valid.


If the data is valid, load it. Else, do something.


Here is an example of a JSON file being used. It's currently not being used for much, besides storing the data.



 
 
 

Recent Posts

See All

Comments


Subscribe?

Thanks for submitting!

©2021 by EMS Games. Proudly created with Wix.com

  • EMS Itch.io
  • Twitter
bottom of page