GMS 2 Use code in json file

Gigicom

Member
Hey,

I‘m trying to figure out how to use pre-defined json files for some item data in my game.

Before, I simply assigned all values to variables and assigned those to a ds_map like this:

GML:
constantData = item.apple;
name = „Apple“;
graphic = spr_ItemApple;
list = ds_list_create();
listVal = ds_list_find_value(anotherList, 1)
With json files, besides the „Apple“ string I can‘t do most of these things. I can‘t use things like a sprite index, data structures, enums or functions. Is there some extension you know of that makes it possible to use code in json files?

Thanks in advance
 

samspade

Member
Not really as that isn't how json works. However, most of what you want can be done. For example, turning what you wrote into valid JSON data:

JSON:
{
    "constantData" : 3,
    "name" : "Apple",
    "graphic" : "spr_ItemApple",
    "list" : [],
}
This would be loaded in as a ds_map. Enums are numbers, so you can save and load them as such. Strings you can save out as strings. Resource ids you can save out as strings (so long as you use the correct functions. Lists will save out as arrays and load in as lists. Data structures that are maps or lists can be saved out as such (and every data structure built into game maker can be converted to those). Methods are the only one I can't think of how to do, but it would be a rare case were you want to.

I would also shamelessly recommend the following series:

 
Top