GMS 2 Game runs fine, but not when using the Debugger [SOLVED]

Hey guys. I'm baffled by this problem:

When I run my game, a json file for language (menu items, etc.) is opened and read into a ds_map in the Create event of my persistent objGameController object.

It all works fine. The game is finished and already available on Steam... but...

... when I try to run the game in the Debugger, it can't find the language data and throws an error:

Code:
############################################################################################
ERROR in
action number 1
of Create Event
for object obj_menu:

Data structure with index does not exist.
 at gml_Script_scrLang (line 16) -               if (!is_undefined(ds_map_find_value(langPage, key)))
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_scrLang (line 16)
called from - gml_Object_obj_menu_Create_0 (line 6) - menu[0] = scrLang(pg, "start"); // "START";
Let me show you an example of the top of this json file:

Code:
{
   "menu": [

       {
           "start": "START",
           .... snip ....
       }
   ... snip ...
   ]
}
As I said, that file works fine outside of the Debugger.

Here's how I get that data:
Code:
// load language file
global.langMap = scrReadJSON("lang_eng.json");
Here's the scrReadJSON script:
Code:
fileName = argument0;

var data = "";
var json = file_text_open_read(working_directory + fileName);
while(!file_text_eof(json))
{
   data += file_text_read_string(json);
   file_text_readln(json);
}
file_text_close(json);

var resultMap = json_decode(data);

//show_debug_message("langMap: " + data);
return resultMap;
And then I can access the map with this:

Code:
pg = "menu";
menu[0] = scrLang(pg, "start");
scrLang looks like this:

Code:
var page = argument[0];
var key = argument[1];
var text = "";

if (ds_exists(global.langMap, ds_type_map))
{
    var langPage = ds_map_find_value(global.langMap, page);
//    if (ds_exists(langPage, ds_type_map))
//   {
        if (!is_undefined(ds_map_find_value(langPage, key))) // ERROR THROWN HERE
        {
            text = ds_map_find_value(langPage, key);
        }
 //   }
}

return text;
So that's all the code. As I say, if I just run the game normally, the language file is read in and the map works fine. But when I use the Debugger, it's unable to find the "langPage" index in global.langMap.

Any ideas why? Thank you.
 
Last edited:
Alright, 3 hours later and I've found a solution:

Json_decode created a ds_map of *ds_lists*, as you can see by the ZEROES in this example:

langMap
... menu page
... ... 0
... ... ... "start" -> "START"
... ... ... "quit" -> "QUIT"
... options page
... ... 0
... ... ... "audio" -> "AUDIO SETTINGS"
... etc.

So, to get my data, I had to get the ds_map stored at the 0 position of each ds_list, like so:

Code:
// Call this script like this: scrLang("how_to_play", "title");

var page = argument[0];
var key = argument[1];
var text = "";

// Check global.langMap exists - this is a ds_map containing a ds_list of ds_maps e.g. menu -> 0 -> "start": "START"
if (ds_exists(global.langMap, ds_type_map))
{
    // get the ds_list from the ds_map
    var langPage = ds_map_find_value(global.langMap, page); // e.g. should return "menu"
    
    // if the ds_list exists...
    if (ds_exists(langPage, ds_type_list))
    {
        // ... get the ds_map at position 0
        var langItems = ds_list_find_value(langPage, 0); // e.g. should return the ds_map for the first position of the "menu" map
        
        if (!is_undefined(ds_map_find_value(langItems, key)))
        {
            text = ds_map_find_value(langItems, key); // e.g. should return the value "START" for the key "start"
        }
    }

}

return text;
Fortunately, this code works in both normal play AND the debugger. Phew!
 
Top