A
AlekM
Guest
Hello!
I am trying to extract lists stored within maps in my game, and I keep getting errors.
I have the maps in my game stored as JSON files. The GM manual states that arrays ([]) within a JSON file are saved as ds_lists and objects ({}) are stored as ds_maps.
So here is my JSON file:
You can see in the JSON file above the file should be expanded to:
So far I have working code that loads in the JSON file, however I have some errors reading from the ds_lists.
This is my code for reading from the ds_map extracted from the JSON:
At line 3 it runs into errors telling me that the id argument is incorrect and it expects some sort of number. If I remove that line it gives me the same error at "var size = ds_list_size(walls);" and if I remove that, I get the same error at "var current_wall = ds_list_find_value(walls, a);"
Any idea how I could fix this?
Thanks,
Alek
I am trying to extract lists stored within maps in my game, and I keep getting errors.
I have the maps in my game stored as JSON files. The GM manual states that arrays ([]) within a JSON file are saved as ds_lists and objects ({}) are stored as ds_maps.
So here is my JSON file:
Code:
{
“walls”: [
{ “name”:”wall1”, “x1”:“0”, “y1”:”0”, “z1”:”0”, “x2”:”10”, “y2”:”0”, “z2”:”10”, “texture”:”brick1_1024”, “hrepeat”:”1”, “vrepeat”:”1”, “shader”:”none”, “material”:”stone” }
]
“floors”: [
{ “name”:”floor1”, “x1”:“0”, “y1”:”0”, “z1”:”0”, “x2”:”10”, “y2”:”10”, “z2”:”0”, “texture”:”grass1_1024”, “hrepeat”:”1”, “vrepeat”:”1”, “shader”:”none”, “material”:”dirt” }
]
}
Code:
ds_map default
|_ds_list walls
|_ds_map walldata
|_ds_list floors
|_ds_map floordata
This is my code for reading from the ds_map extracted from the JSON:
Code:
var defaultMap = ds_map_find_value(global.mapData, "default");
var walls = ds_map_find_value(defaultMap, "walls");
if (!ds_list_empty(walls)) { //It gives an error here for: ds_list_empty argument 1 incorrect type (5) expecting a Number (YYGI32)
var size = ds_list_size(walls);
for (var a = 0; a < size; a++) {
var current_wall = ds_list_find_value(walls, a);
d3d_draw_wall(
ds_map_find_value(current_wall, "x1"),
ds_map_find_value(current_wall, "y1"),
ds_map_find_value(current_wall, "z1"),
ds_map_find_value(current_wall, "x2"),
ds_map_find_value(current_wall, "y2"),
ds_map_find_value(current_wall, "z2"),
back_tex,
ds_map_find_value(current_wall, "hrepeat"),
ds_map_find_value(current_wall, "vrepeat")
)
}
}
Any idea how I could fix this?
Thanks,
Alek