Loading JSON info Error

I keep getting this Error even though the program successfuly uploaded the JSON key :values
1593359473005.png

Apparently the code works and the values show up in my program but like 2 seconds later I get this error. I'm pretty sure I'm missing some code

Create Event
http_get("http://webpage.json")

//Declaring Variable
global.OCH1Q1 = ""
HTTP Event
// Get the answer
json = async_load[? "result"];

//Convert Json to ds_map
map = json_decode(json);
if (map == -1)
{
show_message("Invalid")
exit;
}

if (ds_map_exists(map, "quest"))
{
global.OCH1Q1 = map[? "quest"];
}

The code works sucessfully and the values are displayed from the json that I have stored in a server
Unfortunately a few seconds later I get the Error
Any help with tweaking the code would be greatly appreciated to get it to work
 

Attachments

FrostyCat

Redemption Seeker
Always check async_load[? "id"] and async_load[? "status"] before expecting content. If your file is big enough, there will come a point where you will get multiple "in-progress" HTTP events (status 1, has no result) before the final "done" HTTP event (status 0, has result).

See this reply for the proper procedures, in particular this summary:
The HTTP event should always contain the following:
  • A check for async_load[? "id"] against a previous request ID
  • Checks for all 3 kinds of values for async_load[? "status"] (1, 0 and <0 as of the time of writing)
  • (if dependent on actual response output) Usage of async_load[? "result"] after confirming both async_load[? "id"] and async_load[? "status"]
Anything less is way too casual and asking for unexpected behaviour.
 
Always check async_load[? "id"] and async_load[? "status"] before expecting content. If your file is big enough, there will come a point where you will get multiple "in-progress" HTTP events (status 1, has no result) before the final "done" HTTP event (status 0, has result).

See this reply for the proper procedures, in particular this summary:
I've been trying to come up with the code to check async_load[? "id"] and async_load[? "status"]

how do you check these
HTTP Event
json = async_load[? "result"];

//Convert Json to ds_map
map = json_decode(json);
if (map == -1)
{
show_message("Invalid")
exit;
}

if (ds_map_exists(map, "quest"))
{
global.OCH1Q1 = map[? "quest"];
}

I've been working with this code for hours. Not sure why it works in some programs I work with and with others it doesn't. I know I'm missing something. but not sure how to "Check those Values"... How do I check them... and under which Event do I check them? Thanks...
 

FrostyCat

Redemption Seeker
You would not have to "come up" with anything had you read the example in the linked reply or the one in the Manual's entry for http_get().

My usual pattern reads slightly differently compared to the Manual, but both follow the same procedures:
  1. Call the HTTP function and store the return value in a variable.
  2. In the Async HTTP event, check async_load[? "id"] against the variable from step 1.
  3. If step 2 checks out, also check async_load[? "status"]. Only if it is 0 do you then try to retrieve async_load[? "result"].
Create:
GML:
xhr_webpage = http_get("http://webpage.json");
Async HTTP:
GML:
if (async_load[? "id"] == xhr_webpage) {
    switch (async_load[? "status"]) {
        case 1: break;
        case 0:
            //Convert Json to ds_map
            var map = json_decode(async_load[? "result"]);
            if (map == -1 || !ds_map_exists(map, "quest")) {
                show_message("Invalid")
                exit;
            }
            global.OCH1Q1 = map[? "quest"];
            ds_map_destroy(map);
        break;
        default:
            show_message("Failed to load");
    }
}
 
You would not have to "come up" with anything had you read the example in the linked reply or the one in the Manual's entry for http_get().

My usual pattern reads slightly differently compared to the Manual, but both follow the same procedures:
  1. Call the HTTP function and store the return value in a variable.
  2. In the Async HTTP event, check async_load[? "id"] against the variable from step 1.
  3. If step 2 checks out, also check async_load[? "status"]. Only if it is 0 do you then try to retrieve async_load[? "result"].
Create:
GML:
xhr_webpage = http_get("http://webpage.json");
Async HTTP:
GML:
if (async_load[? "id"] == xhr_webpage) {
    switch (async_load[? "status"]) {
        case 1: break;
        case 0:
            //Convert Json to ds_map
            var map = json_decode(async_load[? "result"]);
            if (map == -1 || !ds_map_exists(map, "quest")) {
                show_message("Invalid")
                exit;
            }
            global.OCH1Q1 = map[? "quest"];
            ds_map_destroy(map);
        break;
        default:
            show_message("Failed to load");
    }
}
Thank You so much... You didn't have to go out of your way to answer my problems.... It seems to be working and I highly appreciate the help alot... You Rock
 
Top