ds_map_find_value Not working

J

John

Guest
I am trying to make an update/maintenance checker in my game. To do this I used the Async - HTTP event to connect to a website and write down the information on it. It works probably 80 percent of the time, but every once in a while it crashes the game (I have attached an image of the message it gives me). It has something to do with the ds_map_find_value not working all the time. Here is the code I am using.

//Check for Update (Ini File)
var re
var eid

eid = ds_map_find_value(async_load,"id");
switch(eid)
{
case async_ini:
re = ds_map_find_value(async_load,"result")
file = file_text_open_write("Maintanance.ini")
file_text_write_string(file,re)
file_text_close(file)
break;
}


If anyone could provide some insight as to why it works most of the time but then crashes sometimes, that would be great! Thanks.
 

Attachments

chamaeleon

Member
I am trying to make an update/maintenance checker in my game. To do this I used the Async - HTTP event to connect to a website and write down the information on it. It works probably 80 percent of the time, but every once in a while it crashes the game (I have attached an image of the message it gives me). It has something to do with the ds_map_find_value not working all the time. Here is the code I am using.

//Check for Update (Ini File)
var re
var eid

eid = ds_map_find_value(async_load,"id");
switch(eid)
{
case async_ini:
re = ds_map_find_value(async_load,"result")
file = file_text_open_write("Maintanance.ini")
file_text_write_string(file,re)
file_text_close(file)
break;
}


If anyone could provide some insight as to why it works most of the time but then crashes sometimes, that would be great! Thanks.
It should be fairly obviuos ds_map_find_value() works perfectly fine, and that your problem is that async_load does not contain what you think it should contain. You need to figure out why this is, rather than trying to coax ds_map_find_value() to make undefined into a defined value. Personally, when I encounter this issue with async_load, I simply json_encode() the packet for debugging purposes and output it using show_debug_message() to the console to see the entirety of the content as received by the async event, checking all values to see what I have overlooked. In your case, do this when re is undefined. Then cross-reference the data displayed with the documentation for the async event to nail down which assumption you have made in your code does not fit the data received.
 

FrostyCat

Redemption Seeker
You are getting this problem because you failed to check async_load[? "status"] for 0. If that happens to be 1 (for download in progress), then there would be nothing in async_load[? "result"] for you to read. You should follow this general form.
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.
GML:
if (async_load[? "id"] == async_ini) {
    switch (async_load[? "status"]) {
        case 1:
            /* Handle in-progress download here */
        break;
        case 0:
            var re = async_load[? "result"];
            var file = file_text_open_write("Maintanance.ini");
            file_text_write_string(file, re);
            file_text_close(file);
        break;
        default:
            /* Handle failed download here */
        break;
    }
}
 
J

John

Guest
Thank you so much! After running testing everything is working consistently.
 
Top