• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GMS2 crashes ds_map_add_map

I have a button and some code that will simply close the app. This works fine by itself. Then I add the following code. At this point the game still runs but as soon as you click on the quit button Gamemaker crashes and says it's become unstable etc.

My problem is 1) Regardless of my code it should never crash in this way. 2) The button code is a completely seperate section of the program and has nothing to do with this so I am confused.

map_data = ds_map_create(); // Generates DS Map for map data

collide_map_data = ds_grid_create(obj_grid.hard_x_limit, obj_grid.hard_y_limit); // Creates tilemap for collision tiles
danger_map_data = ds_grid_create(obj_grid.hard_x_limit, obj_grid.hard_y_limit); // Creates tilemap for danger tiles
decor_map_data = ds_grid_create(obj_grid.hard_x_limit, obj_grid.hard_y_limit); // Creates tilemap for decor tiles

json_encode(collide_map_data);
ds_map_add_map(map_data, "collide", collide_map_data); // Adds collide grid data to dsmap
ds_map_add_map(map_data, "danger", danger_map_data); // Adds danger grid data to dsmap
ds_map_add_map(map_data, "decor", decor_map_data); // Adds decor grid data to dsmap

Any help would be greatly appreciated.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Umm... You are creating DS grids then trying to turn that into a JSON file (which requires a DS map, not a grid) and then assign these JSON DS grids (which don't exist as you can't turn a grid into JSON) to a ds map... this will not work, as they are grids. Not maps. And you don't assign JSON to a ds map, you assign a DS map to a DS map. You are marking a key entry as being a ds map, and not JSON or a DS grid.

I have no idea what you are trying to do, but this is probably not the correct way to do it at all (in general you only need to mark a ds map as containing a ds map when you want to turn it INTO a JSON file for saving or something, otherwise it's pointless).

https://docs2.yoyogames.com/index.html?page=source/_build/3_scripting/4_gml_reference/file handling/json_encode.html
https://docs2.yoyogames.com/index.html?page=source/_build/3_scripting/4_gml_reference/data_structures/ds maps/ds_map_add_map.html
 
I'm unfamiler with how the json stuff works and am new to DS maps. I will try to explain what I want to do.

I am making a map editor.

I have three key layers, collide (The blocks you stand on), danger (spikes, water, lava etc) and decor (trees, signs, windows etc)

I wish to save these to a ds_grid because it saves 2D array information and can be saved easily.

Doing this I will end up with 3 ds_grids that need to be saved. I do not want these to be stored as 3 seperate files.

I will also have additional ds_lists storing stuff like which tileset I was using and the settings and preferences.

I want to store this all in one file. I thought I might be able add a ds_grid to store this.

So I can stores the ds grid lists an other variables within the map.
Umm... You are creating DS grids then trying to turn that into a JSON file (which requires a DS map, not a grid) and then assign these JSON DS grids (which don't exist as you can't turn a grid into JSON) to a ds map... this will not work, as they are grids. Not maps. And you don't assign JSON to a ds map, you assign a DS map to a DS map. You are marking a key entry as being a ds map, and not JSON or a DS grid.

I have no idea what you are trying to do, but this is probably not the correct way to do it at all (in general you only need to mark a ds map as containing a ds map when you want to turn it INTO a JSON file for saving or something, otherwise it's pointless).

In short, can I add a grid to map as a value.

https://docs2.yoyogames.com/index.html?page=source/_build/3_scripting/4_gml_reference/file handling/json_encode.html
https://docs2.yoyogames.com/index.html?page=source/_build/3_scripting/4_gml_reference/data_structures/ds maps/ds_map_add_map.html
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You would have to write out the ds grid as a string using ds_grid_write, then add THAT into the DS map. The map can then be turned into JSON and saved out. So the process would be:

1) Create grid string
2) Add grid string to main DS map
3) Add any further DS lists or maps to the main map
4) Mark all added lists and maps in the main map using the ds_map_add_map/list function
4) Convert main map to JSON
5) Save JSON to disk as a text file

Hope that helps!
 
Top