HTTP Event

This is the sub event that will be triggered by any http call-backs received.

The HTTP Event is one that is triggered by the call back from one of the http_ functions, like http_post_string. It actually generates a ds_map (more commonly known as a "dictionary") that is exclusive to this event and is stored in the special variable async_load (please see the individual functions for code examples that explain the use of this event in further detail). This ds_map has the following structure:

  1. "id": The id which was returned from the command. If you fire off a series of http_ requests then you need to know which one you are getting the reply to, and so you would use this value to compare to the value you stored when you originally sent the request to find the right one.

  2. "status": Returns a value of less than 0 for an error, 0 for success and 1 if content is being downloaded.

  3. "result": The data received (string only), or the path to the file downloaded if you have used http_get_file().

  4. "url": The complete URL you requested.

  5. "http_status": The raw http status code (if available). This returns the standard web status code for most browsers, eg: 304 for "Not Modified" or 204 for "No Content", etc...

That is for when you use the http_post_string() function, but each of the http_ functions may return a slightly different map, so please refer to the manual entry for each function to find out the precise data that is returned for it.

NOTE: The variable async_load is only valid in these events, as the ds_map that is points to is created at the start of the event, then deleted again at the end, with this variable being reset to a value of -1.

NOTE: As async_load creates a ds_map, these functions are particularly useful when coupled with the json_encode and json_decode functions.

Downloading Files

There could also be additional data supplied by this map if you have requested files for downloading. In this case, the "status" will have a value of 1 and the ds_map will hold these extra keys:

  1. "contentLength": This is the size of file that the web server has said you should expect to receive (may be -1 if the server does not return this data).

  2. "sizeDownloaded": The size of the data that has already been downloaded.

Note that the event will not be triggered for every single data packet that is received, but will rather update at any time during the download within the main game loop. Also note that currently this functionality is only available for regular Windows target platforms.

Back: More About Async Events
Next: Dialogues Event
© Copyright YoYo Games Ltd. 2018 All Rights Reserved