GameMaker Studio 2 Desktop

GameMaker Studio 2 Desktop

Rillruin Jul 24, 2018 @ 10:27pm
DS_map issue
Trying to set up multiple layered maps. The code compiles and runs but always returns 0. I tried storing the times in a list but the game crashed every time the data loaded so I switched to a map.

The map stores best times for various difficulty ratings for multiple levels. I plan to add more ds maps to it later.

Note, this is just a test prototype so after storing the data I immediately read the data to test if its working. Eventually the times will be passed to a server to create a worldwide top 10 list of best times for each level-difficulty.

var MainMap = ds_map_create();
var besttimes = ds_map_create();

// map 1
var submap1 = ds_map_create();
ds_map_add(submap1, "Diff1", 117);
ds_map_add(submap1, "Diff2", 225);
ds_map_add(submap1, "Diff3", 300);
ds_map_add(submap1, "Diff4", 412);
// map 2
var submap2 = ds_map_create();
ds_map_add(submap2, "Diff1", 119);
ds_map_add(submap2, "Diff2", 210);
ds_map_add(submap2, "Diff3", 304);
ds_map_add(submap2, "Diff4", 406);

ds_map_add_map(besttimes, "Level1", submap1);
ds_map_add_map(besttimes, "Level2", submap2);

ds_map_add_map(MainMap, "Rooms", besttimes);

// get best time for level 1 difficulty 3
var DSData = ds_map_read(MainMap,"Rooms");
var Level1Data = ds_map_read(DSData,"Level1");
var BestTime = ds_map_read(Level1Data, "Diff3");

show_debug_message("Best Time: " + string(BestTime));

ds_map_destroy(MainMap);
show_debug_message("Test Complete!");

=====
Output
=====

Best Time: 0
Test Complete!
< >
Showing 1-3 of 3 comments
maras Jul 25, 2018 @ 3:14am 
The firts thing I would advise you is to use ds_map_replace instead of ds_map_add
Last edited by maras; Jul 25, 2018 @ 3:16am
Rillruin Jul 25, 2018 @ 8:43am 
Thanks, I changed to using ds_map_replace for the mainmap and level maps. It works either way but will help when updating a best time.

I also discovered ds_map_read only reads strings not maps and was actually destroying the map I was using it to read which isn't good. I don't see any function to get a maps submap.
Rillruin Jul 25, 2018 @ 9:16am 
Still can't find a built in function but using an accessor works.

var LevelMap = ds_map_create();
LavelMap = MainMap[? "level1"];

It's not as intuitive but I can create my own function ds_map_read_map to handle that issue.
< >
Showing 1-3 of 3 comments
Per page: 1530 50

Date Posted: Jul 24, 2018 @ 10:27pm
Posts: 3