ophelius
Member
Ok so I discovered json maps aren't quite like regular maps. Here's what I mean:
I make a map and add a key/value to it, then make a copy, destroy the original, and I can access the new map no problem:
Importing json data is a different story:
I'd like to understand how I can convert json maps into normal ds maps where I can copy the map into a new one and delete the original without it affecting the copy. Any help would be appreciated. Thanks
I make a map and add a key/value to it, then make a copy, destroy the original, and I can access the new map no problem:
Code:
var Map = ds_map_create();
ds_map_add(Map, "test", 10);
var MapCopy = ds_map_create();
ds_map_copy(MapCopy, Map);
ds_map_destroy(Map);
//I can access the copy map no problem
MapCopy[? "test"] = 20;
Code:
var jsonMap = json_decode(buffer_read(buffer_load("File.json"), buffer_string));
//at this point, jsonMap looks and behaves like a normal ds_map, I can navigate it in the debugger like normal
//create a new map to copy the jason map to it
var MapCopy = ds_map_create();
//copy the json map to the new map
ds_map_copy(MapCopy, jsonMap);
//destroy the original
ds_map_destroy(jsonMap);
//This map is not accessible, MapCopy is still only a reference to the original
MapCopy[? "test"] = 500; //ds map not found