HTTP request won't get data from API. Gamemaker Studio 1.4.9

326 views Asked by At

I'm trying to figure out how to get information from a dictionary API in Gamemaker Studio 1.4.9

I'm lost since I can't figure out how to get around the API's server block. All my return shows is a blank result.

Step Event:

if(keyboard_check_pressed(vk_space)){
http_get("https://api.dictionaryapi.dev/api/v2/entries/en/test");
}

HTTP Event:

var requestResult = ds_map_find_value(async_load, "result");

var resultMap = json_decode(requestResult);

if(resultMap == -1) 
{
show_message("Invalid result");
exit;
}

if(ds_map_exists(resultMap,"word")){
    var name= ds_map_find_value(resultMap, "word"); 
    show_message("The word name is "+name);
}

Maybe my formatting is wrong? It's supposed to say the word test in the show_message function, but again, all I get returned is a blank result.

Any help would be appreciated, thanks!

1

There are 1 answers

0
AlexInCube On

You can see through the debugger that the data is coming from the server. But your code does not correctly try to retrieve the Word. https://i.stack.imgur.com/PzRSb.jpg

This code gets this word

show_debug_message("http received")
var requestResult = ds_map_find_value(async_load, "result");

var resultMap = json_decode(requestResult);

if(resultMap == -1) 
{
show_message("Invalid result");
exit;
}

if(ds_map_exists(resultMap,"default")){
    var defaultList = ds_map_find_value(resultMap, "default")
    var Map = ds_list_find_value(defaultList, 0)
    var name= ds_map_find_value(Map, "word"); 
    show_message("The word name is "+name);
}